0

i want to execute multiple tests in parallel, here is some code. i'm using Post method but this doesn't works, can anyone help me?

namespace BusinessLayer.BusinessLogic.UI
{
    [TestFixture]
    [Parallelizable]
    public class nunitlayer : BaseLayer
    {
        [Test]
        public static void test1(IWebDriver driver, WebDriverWait wait, int urlTypeId)
            {
                LoginLayer.LoginTest(driver, wait, urlTypeId);
            }
            [Test]
            public static void test2(IWebDriver driver, WebDriverWait wait, int urlTypeId)
            {
                LoginLayer.ArmenianLoginTest(driver, wait, urlTypeId);
            }
        }
 }



case (int)TestType.nunit:
                        nunitlayer.test1(chrome.driver, chrome.wait, urlTypeId);
                        break;

1 Answer 1

3

You have [Parallelizable] on your test fixture class, nunitlayer. That means it will run in parallel with other fixtures that also have [Parallelizable].

If you want the tests inside nunitlayer to run in parallel with one another, you should do one of the following:

  1. Put [Parallelizable] on each of the tests instead of on the fixture...

    namespace BusinessLayer.BusinessLogic.UI
    {
        [TestFixture]
        public class nunitlayer : BaseLayer
        {
            [Parallelizable]
            [Test]
            public static void test1(IWebDriver driver, WebDriverWait wait, int urlTypeId)
            {
                LoginLayer.LoginTest(driver, wait, urlTypeId);
            }
    
            [Test]
            [Parallelizable]
            public static void test2(IWebDriver driver, WebDriverWait wait, int urlTypeId)
            {
                LoginLayer.ArmenianLoginTest(driver, wait, urlTypeId);
            }
        }
     }
    
  2. Put [Parallelizable(ParallelScope.Children)] on the fixture...

    namespace BusinessLayer.BusinessLogic.UI
    {
        [TestFixture]
        [Parallelizable(ParallelScope.Children)]
        public class nunitlayer : BaseLayer
        {
            [Test]
            public static void test1(IWebDriver driver, WebDriverWait wait, int urlTypeId)
            {
                LoginLayer.LoginTest(driver, wait, urlTypeId);
            }
    
            [Test]
            public static void test2(IWebDriver driver, WebDriverWait wait, int urlTypeId)
            {
                LoginLayer.ArmenianLoginTest(driver, wait, urlTypeId);
            }
        }
    }
    

Either approach will make the tests run in parallel, but it doesn't guarantee they will work. You have not shown where your data for the test method arguments come from. You show a case statement, where the nunit test appears to be called but this is not how NUnit tests are normally run and we don't know if each test is getting (for example) a unique driver. IOW, there are lots of other things that may go wrong and I suspect there's a lot of info about how the tests are run that you have not yet shared.

Sign up to request clarification or add additional context in comments.

2 Comments

i dont understand what you mean, can you edit my code for example?
I expanded the answer... however, looking back at your question it appears that you are running the tests in some non-standard way. The answer will only help you if NUnit is invoking the tests, not if you are calling them from your own code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.