java培训之junit4
Junit主要讲三点:
1. @Test
2. @Before
3. @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations=”classpath:applicationContext.xml”)
@Test
放在要测试的方法上,这个方法就是;一个测试方法,选中方法名点击测试就可以运行。
@Before
是在每个测试方法之前执行,一般我们把每次都要创建的类放在里面:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations=”classpath:applicationContext.xml”)
这两个注释放在类名上,这样,这个类就可以直接测试spring管理的类:
我们可以直接把类直接注入到这个测试类中: