当我执行以下操作时,我会得到一个奇怪的错误:"junit.framework.AssertionFailedError:在com.ac.spring.login.LoginServiceTest中找不到测试我使用的是spring3.0和junit4.x.
测试等级:
@ContextConfiguration(locations={"classpath:META-INF/spring-context.xml","classpath:META-INF/spring-context-test.xml"})
public class LoginServiceTest extends AbstractJUnit4SpringContextTests{
@Autowired
private LoginServiceTestCase loginTestCase;
@Before
public void setup() {
loginTestCase.initialize();
}
@After
public void teardown() {
}
@Test
public void testLoginWithValidAccount() throws Exception {
loginTestCase.setTestName("Validate Login with valid credentials");
loginTestCase.setTestCondition(loginTestCase.CONDITION_USERNAME, "...");
loginTestCase.setTestCondition(loginTestCase.CONDITION_PASSWORD, "...");
loginTestCase.setExpectedResult(loginTestCase.RESULT_IS_ERROR, false);
assertTrue(loginTestCase.isTestPass());
}
....
}
待测试案例:
public class LoginServiceTestCase extends TestCase{
@Autowired
private LoginService loginService; // the class to be tested
......
protected void executeTest() throws Exception {
try {
..... } catch (Exception e) {
isError = true;
}
}
build.xml:
<target name="compile" >
<echo message="-----> Compile Classes from ${src}" />
<mkdir dir="${build}/classes" />
<javac srcdir="${src}"
includes="**/*.java"
destdir="${build}/classes"
debug="on">
<classpath refid="dependencies"/>
</javac>
<copy todir="${build}/classes/META-INF">
<fileset dir="${basedir}/config" includes="**"/>
</copy>
</target>
<target name="batch-test" >
<mkdir dir="${reports.tests}"/>
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<pathelement location="${build}/classes"/>
<path refid="dependencies"/>
</classpath>
<formatter type="plain"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${reports.tests}">
<fileset dir="${src}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
</target>
我哪里错了?
想结束这个问题,但只想告知问题出在ant版本上。从蚂蚁1.5上升到1.7就解决了这个问题。