简体   繁体   中英

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.

// 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 ? Perhaps by specifying .runsettings , or using 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 . The other approaches you list are used by runners in order to tailor what they add to the 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.

Setting the timeout for test cases individually is only possible through the attribute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM