In order to Run a Selenium RC Test using JUnit, we have to add few JUnit Annotations to the Selenium RC Test code:
To start with lets use the following JUnit Annotations in our Selenium RC Tests:
- @Before
- @After
- @Test
As we've already run a Selenium RC Test code in Eclipse IDE i.e Run As -> JUnit Test in our previous post#8 Run the Created Selenium RC Test. Lets look into the Test code and find out whether it has JUnit annotation specified or not.
1. View the Selenium RC Test code which we have already Run as shown below and find out whether the code has JUnit annotations specified:
2. After viewing the Test code its very clear that the Selenium RC Test is using the JUnit Annotations @Before, @Test and @ After.
@Test
All the methods in the class which are specified as @Test as shown in the below screenshot will be executed by the JUnit (i.e. when we select Run As -> JUnit Test ) as shown below:
@Before
All the methods in the class which are specified as @Before as shown in the below screenshot will be executed by the JUnit before executing the methods which are specified as @Test in the same class. @Before is mainly used to setup some objects needed by tests. @Before specified methods are a kind of setup methods. (as shown below):
@After
All the methods in the class which are specified as @After as shown in the below screenshot will be executed by the JUnit after executing the methods which are specified as @Test in the same class (as shown below):
Running the Selenium RC Test code without Annotations:
1. Comment the JUnit annotations from the Selenium RC Test code as shown below:
2. Run the Selenium RC Test code with JUnit Test after commenting the annotations as shown below:
3. Hence, we cannot run the Selenium RC Test with JUnit if the code don't contain any JUnit annotations.
4. Now remove the comments for the annotations as shown below:
5. Try to Run the Selenium RC test using JUnit as shown below:
6. Hence, we can run the Selenium RC Test using JUnit annotations if and only if the test code contains JUnit annotations else JUnit Test option wont be available to Run the test.
Please comment below to feedback or ask questions.
Eclipse Automatically adds the Package Name into the newly created Java Class will be explained in the next post.
No comments:
Post a Comment