首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

junit兑现测试类(在Spring2.5中)

2012-10-29 
junit实现测试类(在Spring2.5中)第一步:创建JAVA项目,也可以是Web项目,加入Spring2.5的Core Lib?创建注入

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());做了比较;

?

热点排行