JUnit Test Template

In this topic I will explain the basic Junit framework template

package com.test;

import org.junit.*;

public class JunitTemplate {

    @BeforeClass
    public static void beforeClassAnnotation() {        
        System.out.println("@BeforeClass - execute one time before any method");
    }

    @AfterClass
    public static void afterClassAnnotation() {       
        System.out.println("@AfterClass - execute one time after last method");
    }

    @Before
    public void beforeAnnotation() {       
        System.out.println("@Before - execute before every method");
    }

    @After
    public void afterAnnotation() {      
        System.out.println("@After - execute after every method");
    }

    @Test
    public void testAnnotation() {       
        System.out.println("@Test - first test method");
    }

    @Test
    public void testAnnotation1() {       
        System.out.println("@Test - second test method");
    }
}

After execution above test execution log generated as below:

@BeforeClass - execute one time before any method
@Before - execute before every method
@Test - second test method
@After - execute after every method
@Before - execute before every method
@Test - first test method
@After - execute after every method
@AfterClass - execute one time after last method     

No comments:

Post a Comment

Leave your comments, queries, suggestion I will try to provide solution