0

I have a small problem, I have created some Selenium tests. The problem is I can't order the testcases I have created. I know unit testing should not be ordered but this is what I need in my situation. I have to follow these steps: login first, create a new customer, change some details about the customer and finally log out.

Since there is no option to order unit tests in NUnit I can't execute this.

I already tried another option, to create a unittest project in Visual Studio, because Visual Studio 2012 has the ability to create a ordered unit test. But this is not working because I can't run a unit test while I am running my ASP.NET project. Another solution file is also not a good option because I want to verify my data after it has been submitted by a Selenium test.

Does someone of you have another solution to solve my problem?

Sander
  • 378
  • 2
  • 13

1 Answers1

1

If you want to test all of those steps in a specific order (and by the sounds of it, as a single session) then really it's more like an acceptance test you are talking about; and in that case it's not a sin to write more complex test methods and Assert your conditions after each step.

If you want to test each step in true isolation (a pure unit test) then each unit test must be capable of running by itself without any reference to any other tests; but when you're testing the actual site UI itself this isn't really an option for you.


Of course if you really you want to have every single test somehow setup every single dependency without reference to any other actions (e.g in the last test you would need to fake the login token, your data layer will have to pretend that you added a new customer, etc. A lot of work for dubious benefit...)

I say this based on the assumption that you already have unit tests written for the server-side controllers, layers, models, etc, that you run without any reference to the actual site running in a browser and are therefore confident that the various back-end part of your site do what they are supposed to do


In your case I'd recommend more of a hybrid integration/acceptance test

void Login(IWebDriver driver)
{
   //use driver to open browser, navigate to login page, type user/password into box and press enter

}

void CreateNewCustomer(IWebDriver driver)
{
  Login(driver);
  //and then use driver to click "Create Customer" link, etc, etc

}

void EditNewlyCreatedCustomer(IWebDriver driver)
{
  Login(driver);
  CreateNewCustomer(driver);
  //do your selenium stuff..

}

and then your test methods:
[Test]
void Login_DoesWhatIExpect()
{
  var driver = new InternetExplorerDriver("your Login URL here");   
  Login(driver);
  Assert(Something);
}
[Test]
void CreateNewCustomer_WorksProperly()
{
   var driver = new InternetExplorerDriver("your Login URL here");   
   CreateNewCustomer(driver);
   Assert(Something);
}
[Test]
void EditNewlyCreatedCustomer_DoesntExplodeTheServer()
{
   var driver = new InternetExplorerDriver("your Login URL here");   
   EditNewlyCreatedCustomer(driver);
   Assert(Something);
}

In this way the order of the specific tests do not matter; certainly if the Login test fails then the CreateNewCustomer and EditNewlyCreatedCustomer tests will also fail but that's actually irrelevant in this case as you are testing an entire "thread" of operation

Stephen Byrne
  • 7,400
  • 1
  • 31
  • 51