[英]How do I specify test timeout for custom NUnit Test Runner?
I run unit tests from code, and my tests can be infinitely long.我从代码运行单元测试,我的测试可以无限长。 NUnit keeps running until all tests are closed hence my test session never closes. NUnit 一直运行直到所有测试都关闭,因此我的测试 session 永远不会关闭。
// Get an interface to the engine
Engine.ITestEngine engine = Engine.TestEngineActivator.CreateInstance();
// Create a simple test package - one assembly, no special settings
Engine.TestPackage package = new Engine.TestPackage(_testProjectAssemblyPath);
// Get a runner for the test package
var runner = engine.GetRunner(package);
XmlNode testSessionResult = runner.Run(listener: new Listener1(), Engine.TestFilter.Empty);
Is it possible to specify a time out without using the Timeout
NUnit attribute ?是否可以在不使用Timeout
NUnit 属性的情况下指定超时? Perhaps by specifying .runsettings
, or using ISettings ?也许通过指定.runsettings
或使用ISettings ?
I tried firing up a task with a timeout, however, this prevents me to see the failing tests, which is mandatory in my use case.我尝试使用超时启动任务,但是,这阻止了我看到失败的测试,这在我的用例中是强制性的。
The NUnit engine only reads settings from the TestPackage
. NUnit 引擎仅从TestPackage
读取设置。 The other approaches you list are used by runners in order to tailor what they add to the TestPackage
.跑步者使用您列出的其他方法来定制他们添加到TestPackage
的内容。
To set a general timeout, which applies to all the tests in the run, use something like this...要设置适用于运行中所有测试的一般超时,请使用类似这样的东西......
package.AddSetting("DefaultTimeOut", 4000);
The above will give each individual test case 4 seconds before it is cancelled.以上将在取消之前给每个单独的测试用例 4 秒。
Setting the timeout for test cases individually is only possible through the attribute.只能通过属性单独设置测试用例的超时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.