NUnit 中的断点和停止调试 - 如何终止测试?
Breakpoints in NUnit and stopping Debugging - How to kill a Test?
抱歉,这是一个奇怪的用例,但请耐心等待。
我有一个简单的 TestFixture(如下所示),除了调用 PrimeService 来检查数字是否为素数之外,只要命中例程(即 OneTimeSetup、Setup、OneTimeTearDown 等),它就会记录到文件中。 )
有人可以向我解释为什么如果我 运行 以下场景,TestFixture 运行 是完整的吗?
- 我在断言之前的测试中放置了一个断点。
- 我在 VS (2019) 中开始“调试测试”过程
- 当测试暂停时(自然会在第一次测试时),我按下“停止调试”按钮 (shift F5)
如果我去打开我的日志文件,我会看到所有 3 个测试 运行,以及 TearDown 和最终 Teardown。
抱歉,我只想了解幕后发生的事情,以及是否有办法终止暂停的测试 运行。
谢谢。
[TestFixture]
public class PrimeService_IsPrimeShould
{
private NerdAnalysis.PrimeService _primeService;
private System.IO.StreamWriter file;
[OneTimeSetUp]
public void OneTimeSetup()
{
file = new System.IO.StreamWriter(@"C:\Users\Fozzy Bear\source\repos\NunitTutorial\MyFile.txt");
file.WriteLine("One time SetUp");
}
[SetUp]
public void Setup()
{
_primeService = new NerdAnalysis.PrimeService();
file.WriteLine("Setup");
}
[TestCase(-1)]
[TestCase(0)]
[TestCase(1)]
public void IsPrime_lessthan2_pass(int value)
{
file.WriteLine("Running test for value " + value);
var result = _primeService.IsPrime(value);
Assert.IsFalse(result, "${ value} should not be prime");
var breakLine = "break";
Assert.Pass();
}
[OneTimeTearDown]
public void FinalTearDown() {
file.WriteLine("Final Teardown");
file.Close();
file.Dispose();
}
[TearDown]
public void TearDown()
{
file.WriteLine("Tear down");
}
来自 http://msdn.microsoft.com/en-us/library/406kfbs1.aspx
Stop Debugging terminates the process you are debugging if the program
was launched from Visual Studio. If you attached to the process,
instead of launching it from Visual Studio, the process continues
running. If you want to terminate attached processes, you can
terminate a single process from the Processes window or terminate all
attached process with the Terminate All command.
抱歉,这是一个奇怪的用例,但请耐心等待。
我有一个简单的 TestFixture(如下所示),除了调用 PrimeService 来检查数字是否为素数之外,只要命中例程(即 OneTimeSetup、Setup、OneTimeTearDown 等),它就会记录到文件中。 )
有人可以向我解释为什么如果我 运行 以下场景,TestFixture 运行 是完整的吗?
- 我在断言之前的测试中放置了一个断点。
- 我在 VS (2019) 中开始“调试测试”过程
- 当测试暂停时(自然会在第一次测试时),我按下“停止调试”按钮 (shift F5)
如果我去打开我的日志文件,我会看到所有 3 个测试 运行,以及 TearDown 和最终 Teardown。
抱歉,我只想了解幕后发生的事情,以及是否有办法终止暂停的测试 运行。
谢谢。
[TestFixture]
public class PrimeService_IsPrimeShould
{
private NerdAnalysis.PrimeService _primeService;
private System.IO.StreamWriter file;
[OneTimeSetUp]
public void OneTimeSetup()
{
file = new System.IO.StreamWriter(@"C:\Users\Fozzy Bear\source\repos\NunitTutorial\MyFile.txt");
file.WriteLine("One time SetUp");
}
[SetUp]
public void Setup()
{
_primeService = new NerdAnalysis.PrimeService();
file.WriteLine("Setup");
}
[TestCase(-1)]
[TestCase(0)]
[TestCase(1)]
public void IsPrime_lessthan2_pass(int value)
{
file.WriteLine("Running test for value " + value);
var result = _primeService.IsPrime(value);
Assert.IsFalse(result, "${ value} should not be prime");
var breakLine = "break";
Assert.Pass();
}
[OneTimeTearDown]
public void FinalTearDown() {
file.WriteLine("Final Teardown");
file.Close();
file.Dispose();
}
[TearDown]
public void TearDown()
{
file.WriteLine("Tear down");
}
来自 http://msdn.microsoft.com/en-us/library/406kfbs1.aspx
Stop Debugging terminates the process you are debugging if the program was launched from Visual Studio. If you attached to the process, instead of launching it from Visual Studio, the process continues running. If you want to terminate attached processes, you can terminate a single process from the Processes window or terminate all attached process with the Terminate All command.