4

I'm using Java and Selenium Webdriver, but there is something that I don't understand. Do I need to create separate classes for each test, or I just need to create one class and in that class have all my tests.

Can someone help me with this?

4

(Unit)Test-runners wrap their tests in a class for execution. You can place multiple tests into a single class. Often an annotation is used to show the class method is a test. jUnit uses @Test, MStest uses <TestMethod> and nUnit uses [Test]

Personally I group tests that test the same part of the application into a single class. This way the class files do not become to big and I can add helper functions close to the tests.

Now you are thinking about how to structure your automated tests also be sure to read about the Page Object pattern. As it the current best practice in preventing code duplication in tests.

| improve this answer | |
  • Great Niels! Thank you for your reply. I also talked about this with my manager and he also suggested that if the tests are dependant, then use a single class for those dependant tests. If the tests are independent, then use more classes and just add them to the executable xml that run all the tests. – Laurenzanoster Jan 26 '16 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.