I am trying to execute a code (in which I am auto wring a property) before executing any junit test using Before Class annotation but here problem is that annotated method called before application context load due to this I get the null value in property (helloWorld).
Please refer code for the same
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/SpringBeans.xml")
public class JunitTest {
@Autowired
private static HelloWorld helloWorld;
@BeforeClass
public static void methodBefore(){
helloWorld.printHello();
System.out.println("Before Class");
}
@Test
public void method1(){
System.out.println("In method 1");
}
@Test
public void method2(){
System.out.println("In method 2");
}
@Test
public void method3(){
System.out.println("In method 3");
}
@Test
public void method4(){
System.out.println("In method 4");
}
@AfterClass
public static void methodAfter(){
System.out.println("After Class");
}
}
In the same way I want to execute some code after executing all junit test.
please suggest how can I achieve above things