项目使用MyEclipse8.6开发,并且使用的Spring,下面是我的自动化测试脚本,呵呵
/**
* 整个测试下BeanFactory只运行一次
* @author Administrator
*
*/
public class BeanFactory {
private static ApplicationContext context ;
static{
context = new ClassPathXmlApplicationContext("applicationContext.xml");
}
private BeanFactory(){
}
public static Object getBean(String beanName){
return context.getBean(beanName);
}
}
/**
* 一个简单的测试
*/
public class SeoKeyServiceTest {
static SeoKeyService seoKeyService;
@BeforeClass
public static void init(){
seoKeyService = (SeoKeyService)BeanFactory.getBean("seoKeyService");
}
@Test
public void testBasic(){
SeoKeyWord skw = new SeoKeyWordTestFactory().getBrandKeyWord();
skw = seoKeyService.saveSeoKeyWord(skw);
assertNotNull(skw);
seoKeyService.deleteSeoKeyWord(skw.getId());
skw = seoKeyService.getSeoKeyWordById(skw.getId());
assertTrue(skw == null);
}
}
下面是我的自动化测试脚本,没有complie过程,使用Eclipse的 Build Automatically
<project default="junit" name="My First Ant project " >
<description>
***单元测试
</description>
<property name="junit.data" value="report"></property>
<path id="classpath.main">
<fileset dir="../s**mmon/lib" includes="**/*.jar" excludes="b*eb/ant.jar"></fileset>
<fileset dir="D:/javalab/junit" includes="**/*.jar"></fileset>
</path>
<target name="init" >
<delete dir="${junit.data}"></delete>
</target>
<target name="junit" depends="init">
<mkdir dir="${junit.data}"/>
<junit printsummary="yes" fork="true" haltonfailure="false">
<classpath>
<path refid="classpath.main"></path>
<pathelement location="../s**common/bin"/>
<pathelement location="WebRoot/WEB-INF/classes"/>
</classpath>
<formatter type="xml"/>
<batchtest haltonfailure="false"
todir="${junit.data}">
<fileset dir="test" includes="**/*Test.java" >
</fileset>
</batchtest>
</junit>
</target>
</project>

本文介绍了一个使用MyEclipse 8.6进行自动化测试的例子,该例子基于Spring框架,并通过JUnit进行单元测试。示例中定义了BeanFactory类用于初始化Spring上下文并获取Bean实例,同时展示了一个具体的测试类SeoKeyServiceTest,该测试类包含了测试方法的实现。
2641

被折叠的 条评论
为什么被折叠?



