junit实现测试类(在Spring2.5中)
第一步:
创建JAVA项目,也可以是Web项目,加入Spring2.5的Core Lib
?
创建注入类(测试用)
?
修改applicationContext.xml文件
?
内容如下:
?
注入类:
?
测试类
?
package nell;import static org.junit.Assert.*;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestE {@Testpublic void haha(){ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");Animal aa=(Animal)ac.getBean("animal");assertEquals("123",aa.getOne());assertEquals("小到堆",aa.getTwe());}}?
注意点:
@Test
在上面打入@Test,如果出现报错,右键加入Jar包,在MyEclipse Lib下面有个Spring2.5 Testing Support Lib包
因为Spring已集成
好了,把Junit运用了,assertEquals("123",aa.getOne());做了比较;
?