【发布时间】:2015-08-09 05:11:28
【问题描述】:
我正在尝试在使用 Before Class 注释执行任何 junit 测试之前执行代码(我在其中自动拧属性),但这里的问题是在应用程序上下文加载之前调用的带注释的方法,因此我得到了 null 值属性 (helloWorld)。
请参考相同的代码
@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");
}
}
以同样的方式,我想在执行完所有 junit 测试后执行一些代码。
请建议我如何实现上述目标
【问题讨论】: