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?

Niels van Reijmersdal
32.7k4 gold badges59 silver badges125 bronze badges
asked Jan 25, 2016 at 15:32
1

1 Answer 1

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.

answered Jan 25, 2016 at 16:42
1
  • 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. Commented Jan 26, 2016 at 19:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.