Selenium WebDriver With JUnit Interview Questions With Answers Part 12

Part 12

53 : Which Is the latest version of JUnit.

Answer : Current latest version of JUnit Is 4.12-beta-2. This can change In future. To check latest released version of JUnit, You can Visit JUnit Official WebSite.
54 : Tell me different JUnit annotations and Its usage.

Answer : JUnit has bellow given different annotations.
  • @Test  : @Test annotation Is useful to Identify method as a Test method from software automation test script.
  • @Before : @Before annotation method will be executed before each and every @Test method.
  • @After : @After annotation method will be executed after each and every @Test method.
  • @BeforeClass : @BeforeClass annotation method will be executed before all @Test methods In a class(Means before first @Test method).
  • @AfterClass : @AfterClass annotation method will be executed after all @Test method In a class(Means after last @Test method).
  • @Ignore : @Ignore annotation Is useful to exclude @Test method from execution. VIEW EXAMPLE
  • @Test(timeout=1000) : You can set @Test method execution timeout. This @Test method fails Immediately when Its execution time cross 1000 milliseconds.
VIEW PRACTICAL EXAMPLE of JUnit annotations with selenium webdriver software testing tool.

55 : Write sample JUnit @Test method that passes when expected ArithmeticException thrown.

Answer : Sample JUnit @Test to pass on expected ArithmeticException Is as bellow.
@Test(expected = ArithmeticException.class)  
public void excOnDivision() {  
    int i = 5/0;
}

VIEW PRACTICAL EXAMPLE for Junit Timeout And Expected Exception software Test.

56 : Write sample JUnit @Test method that fails when unexpected ArithmeticException thrown.

Answer : Sample JUnit @Test to fail on unexpected ArithmeticException Is as bellow.
@Test  
public void excOnDivision() {  
    int i = 5/0;
}

57 : What are the advantages of TestNG over JUnit.

Answer : Advantages of TestNG over JUnit JUnit are as bellow.



  • TestNG Annotations are simple and Easy to understand.
  • Easy to parameterize the software test cases In TestNG.
  • Easy to run software automation test cases In parallel.
  • Can generate Interactive XSLT test execution reports using TestNG.



  • No comments:

    Post a Comment