JUnit Tutorial

What is JUnit?

JUnit is the unit testing Java framework use for writing repeatable tests. When uses with Selenium, helps integrating various modules implemented under any automation framework For Exmaple, we have a code which reads the xls file, 2nd code that creates the database connectivity, 3rd code that generates the HTML reports and 4th code that generates some logs and there are other Java files written for performing various operations like database handling, generating test results etc.

Now we have a controller placed in between these codes which will maintain the flow of execution i.e. a framework JUnit or TestNG If we want to run all these scripts in single execution then we need a controller which will going to handle all these executions sequentially using differnt JUnit annotations.

Training will be provided on both TestNG and JUnit Java framework since there are some companies that are using JUnit and some are on TestNG.

How to configure JUnit in Eclipse?



Getting Started with JUnit:

  • create a new project i.e. Junit_module

  • Now right click on the project and click on build path then click on Add library

  • Select JUnit and click on Next
  • So Junit library comes inbuilt inside eclipse. You do not need to download it form the internet.
  • Now select the Junit version i.e. Junit 4 and then click on finish.
  • Create a new class i.e. testingjunit
  • We will not create any main function since there is no main function in Junit we only have test annotations in JUnit.

    Some of the JUnit Annotations:

    @test
    @After
    @Before
    @BeforeClass
    @AfterClass
    @ignore � how to ignore a test case