最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Can setup methods run in parallel for NonParallelizable tests? - Stack Overflow

programmeradmin2浏览0评论

I have a test method with a NonParallelizable attribute. The question is:

Can it be, that TestSetup() method runs in parallel to the running TestMeth() of previous test case and only TestMeth() methods are "locked"?

I see NonParallelizable can be set for each method, also for TestSetup().

public class TestClass
{
    [SetUp]
    public void TestSetup()
    {
        //some init stuff, which must be done for each test case nonparallel to the running tests/test cases
    }

    [NonParallelizable, TestCaseSource("SomeTestCaseProvider")]
    public void TestMeth()
    {
        //...
    }

}

I have a test method with a NonParallelizable attribute. The question is:

Can it be, that TestSetup() method runs in parallel to the running TestMeth() of previous test case and only TestMeth() methods are "locked"?

I see NonParallelizable can be set for each method, also for TestSetup().

public class TestClass
{
    [SetUp]
    public void TestSetup()
    {
        //some init stuff, which must be done for each test case nonparallel to the running tests/test cases
    }

    [NonParallelizable, TestCaseSource("SomeTestCaseProvider")]
    public void TestMeth()
    {
        //...
    }

}
Share Improve this question asked Mar 28 at 19:29 RekshinoRekshino 7,3352 gold badges24 silver badges50 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

The documentation about NonParallelizable says that

When used on a test fixture or method, that test will be queued on the non-parallel queue and will not run while other tests marked as Parallelizable are being run.

Again via the docs the Setup method is supposed to run "just before each test method is called.".

I haven't explicitly tested/looked at the source code, but logically since Setup depends on TestMethod to be "just before runnable" and TestMethod depends on parallelizable code to have finished, it should follow that Setup should also depend on other parallelizable tests to have finished before it executes.

SetUp, TearDown and the Test method itself, all run on the same thread. When the docs talk about queuing a "test" it refers to all three. Any Parallelizable` or `NonParallelizable` attribute that appears on the test method applies to the "test" as a whole.

It has to work that way, since the SetUp prepares the environment in which the test method will run and the TearDown cleans it up.

发布评论

评论列表(0)

  1. 暂无评论