Start UnitTesting – Junit, The begining

Maven Dependency for Junit


Important Annotations

@BeforeClass – runs once before any test method in class
@AfterClass – runs once after all the tests in class have been run
@Before – runs before test method
@After – runs after the test method
@Test – This is test method to run.

Lets write a sample test class with all these Annotations

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class StratUnitTesting {

    public StratUnitTesting() {

    @BeforeClass  // runs only once before the class
    public static void setUpClass() {
        System.out.println("inside @BeforeClass");

    @AfterClass // runs onlyu once after the class
    public static void tearDownClass() {
        System.out.println("inside @AfterClass");

    @Before //run before the test method
    public void setUp() {
       System.out.println("inside @Before");

    @After //run after the test method
    public void tearDown() {
        System.out.println("inside @After");

     public void testMethod1() {
         System.out.println("inside @Test testMethod1");

     public void testMethod2() {
         System.out.println("inside @Test testMethod2");
     public void testMethod3() {
         System.out.println("inside @Test testMethod3");



About sivateja

I am a professional graduate..I am passionate about Latest Technology.
This entry was posted in Testing and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s