NUnit Test Run Order

前端 未结 16 1326
名媛妹妹
名媛妹妹 2020-12-02 11:44

By default nunit tests run alphabetically. Does anyone know of any way to set the execution order? Does an attribute exist for this?

16条回答
  •  伪装坚强ぢ
    2020-12-02 12:18

    There are very good reasons to utilise a Test Ordering mechanism. Most of my own tests use good practice such as setup/teardown. Others require huge amounts of data setup, which can then be used to test a range of features. Up till now, I have used large tests to handle these (Selenium Webdriver) integration tests. However, I think the above suggested post on https://github.com/nunit/docs/wiki/Order-Attribute has a lot of merit. Here is an example of why ordering would be extremely valuable:

    • Using Selenium Webdriver to run a test to download a report
    • The state of the report (whether it's downloadable or not) is cached for 10 minutes
    • That means, before every test I need to reset the report state and then wait up to 10 minutes before the state is confirmed to have changed, and then verify the report downloads correctly.
    • The reports cannot be generated in a practical / timely fashion through mocking or any other mechanism within the test framework due to their complexity.

    This 10 minute wait time slows down the test suite. When you multiply similar caching delays across a multitude of tests, it consumes a lot of time. Ordering tests could allow data setup to be done as a "Test" right at the beginning of the test suite, with tests relying on the cache to bust being executed toward the end of the test run.

提交回复
热议问题