I am writing some unit tests in VS 2010 using Selenium and C#. I have a couple of test cases. For instance, some of my test cases are:
Launch the website: http://localhost:8080. Verify the Sign on page is present. Enter Username and Password, and Log in.
Check to see if Search tab is present. Click on Search tab. Verify the tabs Search Books, Search Images, and Search Web are present.
Click on Search Books. Type "C-Sharp for Dummies". Click Search. Verify appropriate results are returned.
Now, my question is: Is it a better idea to create separate classes for each of the above test cases or is it better to combine them to one class, and just have separate methods?
All three test cases are related to one another. By this I mean, executing #2 requires #1 to be complete first, and #3 requires #2 to complete first. If I make separate classes, I believe I will need to call the method in #1 in the class #2, and call methods in #1 and #2 in the class #3.
I am not so sure what would be a good idea for this. Thanks in advance.
If you use something like NUnit to control your selenium testing then point 1 can be inside a SetUp
as we can assume that all (or most) of your tests will need to log in to do anything. Since all your tests will fail if this fails it doesn't really need independent testing.
If you consider the interaction between point 2 and 3 there is some cross over and there is some independent testing.
If you consider the crossover testing (clicking the Search Books link) point 3 depends on point 2 to run before it is run, thus there is no point having two separate tests, if test 2 fails then test 3 will always fail.
In point 2 you are testing that three links appear, but in test 3 you are only clicking one of them thus point 2 could fail but point 3 succeed, thus they should be separate tests., however point 3 does not depend entirely on point 2.
Personally you have two options, if you are also going to test "Search Images" and "Search Web" then you should not have point 2 at all. The assertion of the visibility of the link and the clicking of the link should all be melded into point 3.
If you are not going to test "Search Images" and "Search Web" then it is fine to have point 2. However test 3 should not call point 2's method as it tests extra functionality that point 3 does not care about. It should assume the "Search Books" link is there and click it independently of point 2.
If the tests are related, I would keep them in one file, but this is under the assumption on how many tests you have, because I would not want to have just one file with tons of tests, so I would logically put related tests in separate files. I wouldn't get too boggled down on this especially if you don't have too many tests right now.
You can also try WatiN as an alternative to Selenium.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With