0

I have unit tests in my C# project (VisualStudio 2015,Nunit). I want to check methods in many different situations with different parameters, to achieve that, i used TestCases. Each test method works very slow - few seconds, and TestCases count in my projects grows.

So now testing takes some minutes. I tried to parallel these tests, by moving each test to separate TestFixture - Nunit allows to run TestFixtures in parallel - Nunit Documentation. It slightly changed situation, but not significantly. I want to parallel tests not on the TestFixture level, but on testcases level. I don't know how to do it. I have read documentation for Nunit, Xunit, MBUnit etc. and didn't found the answer.

How can i run my tests in parallel, in such way that testscases will run simultaneously? Which framework to use?

My tests example in pseudocode:

public static class GeneralTestCases
{
    public static IEnumerable TestStoresCredentials
    {
        get
        {
            yield return new TestCaseData( ... ).SetName("incorrect password");
            ...
            yield return new TestCaseData( ... ).SetName("incorrect login");
        }
    }
}

[ TestFixture ]
[ Parallelizable ]
internal class GetProducts : BaseTest
{
    [ Test ]
    [ TestCaseSource( typeof( GeneralTestCases ), "TestCases" ) ]
    public void ReceiveProducts( TestCase case )
    {
        // ------------ Arrange
        var service = CreateService( case.User, case.Key, ... );

        // ------------ Act
        var serviceResponse = service.GetProducts(case.SpecialType);

        // ------------ Assert
        ...
        serviceResponse.Message.Should().NotBeNullOrEmpty();
        ...
    }
}


[ TestFixture ]
[ Parallelizable ]
internal class GetOrders : BaseTest
{
    [ Test ]
    [ TestCaseSource( typeof( GeneralTestCases ), "TestCases" ) ]
    public void ReceiveOrders( TestCase case )
    {
        // ------------ Arrange
        var service = CreateService( case.User, case.Key, ... );

        // ------------ Act
        var serviceResponse = service.GetOrders(case.SpecialType);

        // ------------ Assert
        ...
        serviceResponse.Message.Should().NotBeNullOrEmpty();
        ...
    }
}

enter image description here

Update1: I'm thinking about nCrunch, but i don't will it help or not

Maxim Kitsenko
  • 2,042
  • 1
  • 20
  • 43
  • maybe this helps https://stackoverflow.com/questions/3313163/how-can-i-run-nunit-tests-in-parallel – IamK Nov 02 '16 at 21:45

3 Answers3

0

xUnit runs each test class (test collection) in parallel by default.

More info here.

Aleksey L.
  • 35,047
  • 10
  • 74
  • 84
  • Thanks! If i understand correctly, this approach equals to my current implementation, isn't it? Each class can be run in parallel, that means i need to create new once class for each test case. That leads to duplication - 100500 classes with the same members. I need something like horizontal scale. Look at picture in my question. – Maxim Kitsenko Nov 03 '16 at 08:19
  • I think running 100500 in parallel will not bring you better results. Anyway you should define some limit - it will depend on machine(CPU, memory etc.) and what kind of operations tests are doing (CPU bound or IO bound) – Aleksey L. Nov 03 '16 at 09:58
  • Off course i'm talking about few hundreds. Even if it fill be 100500 - it will be much faster to create 100500 testcases instead of 100500 tests – Maxim Kitsenko Nov 03 '16 at 12:49
0

After some research i found 2 ways to run tests simultaneously .

  1. Nunit + Ncrunch it allows to run tests in parallel ( test cases parallelization supported). But for me this way is not convenient. I don't like Ncrunch GUI and it takes time to configura it in correct way (long running tests threshold settings, multithreading settings etc). Also Ncrunch isn't free.
  2. Nunit + Nunit tests runner console. I choose this way. It allows to run tests in parallel, it is free, easy to config, can be runned from console. You can configure to run a lot of tests in parallel in 1 conosle window, or run multiple consoles, each one runs 1 test at time
Maxim Kitsenko
  • 2,042
  • 1
  • 20
  • 43
0

I've done this using NUnit. I have a working project which executes browser tests in method-level.

https://github.com/atmakur/WebTestingFramework

Deepak
  • 43
  • 1
  • 8