0

当我执行以下命令时,我收到一个奇怪的错误:“junit.framework.AssertionFailedError: No tests found in com.ac.spring.login.LoginServiceTest 我正在使用 spring 3.0 和 junit 4.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;
    }
    } 

构建.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>

我哪里错了?

4

1 回答 1

0

想结束这个问题 - 但只是想告知问题出在 ant 版本上。从 ant 1.5 升级到 1.7 解决了这个问题。

于 2013-02-09T05:15:53.583 回答