查看完整版本: 求助:ant执行单元测试的问题

limitmx 2008-2-20 19:12

求助:ant执行单元测试的问题

倒腾了半天,就剩下ant执行单元测试这关过不去了,产生的报告一直提示找不到类,具体如下
Testsuite: crs.bd.bonus_case.BcsCsapBDTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
        Caused an ERROR
crs.bd.bonus_case.BcsCsapBDTest
java.lang.ClassNotFoundException: crs.bd.bonus_case.BcsCsapBDTest

各位大侠帮帮忙啊

limitmx 2008-2-20 19:12

忘记了贴ant代码了  
<target name="unittest">
    <junit printsummary="yes" haltonfailure="yes" fork="yes">

      <classpath refid="project.class.path"></classpath>
      <formatter type="xml" />
      <formatter type="plain" />

      <batchtest fork="yes" todir="${report}" >
        <fileset dir="${src}">
          <include name="**/*Test.java" />
        </fileset>
      </batchtest>
    </junit>
  
    <!--<junitreport todir="${report}" >
         <fileset dir="${report}" >
            <include name="TEST-*.xml"/>
         </fileset >
         <report format="frames" todir="${report}"/>
    </junitreport> -->
  </target>

limitmx 2008-2-21 23:08

已经解决 原来是classpath问题 低级错误 惭愧

berniebd 2008-2-27 18:14

你好,我也被ant的这个配置文件卡住了,下面是build.xml文件的代码,还有我的程序的目录格式
<?xml version="1.0" encoding="utf-8"?>
<project name="test" default="test" basedir=".">
       <!--配置基本属性-->
       <property name="src" value="src"/>
       <property name="build" value="build"/>
       <property name="lib" value="lib" />
       <property name="dist" value="dist"/>
       <property name="classpath" location="${src}"/>

       <!--配置测试报告的属性-->
       <property name="report"   value="report"/>
       <property name="report.xml"  value="${report}/junit/xml"/>
       <property name="report.html" value="${report}/junit/html"/>

       <!--配置运行时classpath-->
       <path id="classpath.run">
              <pathelement path="${classpath}"/>
              <fileset dir="${lib}">
                     <include name="*.jar"/>
              </fileset>
       </path>

                   <!--配置测试时classpath-->
       <path id="classpath.test">
              <path refid="classpath.run"/>
              <path location="${dist}/lib/test-${DSTAMP}.jar"/>
       </path>

       <!--任务初始化-->
       <target name="init" >
              <tstamp/>
              <delete dir="${build}"/>
              <delete dir="${report}"/>
              <delete dir="${dist}"/>
              <mkdir dir="${build}"/>
       </target>

       <!--配置编译任务-->
       <target name="compile" depends="init">
              <javac srcdir="${src}" destdir="${build}">
                      <classpath refid="classpath.run" />
              </javac>
       </target>

       <!--配置打包任务-->
       <target name="dist" depends="compile">
              <mkdir dir="${dist}/lib"/>
              <jar jarfile="${dist}/lib/test-${DSTAMP}.jar" basedir="${build}"/>
       </target>

       <!--配置运行任务-->
       <target name="run" depends="compile, dist">
         <java classname="com.junit.testAddAndSubtract">
             <classpath>
                     <path refid="classpath.run"/>
              </classpath>
         </java>
       </target>

       <!--配置JUnit测试,打印测试结果-->
       <target name="test" depends="compile, dist">
              <mkdir dir="${report.xml}"/>
              <mkdir dir="${report.html}"/>
              <junit printsummary="yes" haltonfailure="no">
                     <classpath refid="classpath.run"/>
                     <formatter type="xml"/>
                     <batchtest fork="yes" todir="${report.xml}">
                            <fileset dir="${src}" includes="**/test*.java"/>
                     </batchtest>
              </junit>
              <junitreport todir="${report.html}">
                     <fileset dir="${report.xml}">
                            <include name="*.xml"/>
                     </fileset>
                     <report format="frames" todir="${report.html}"/>
              </junitreport>
       </target>
</project>

|--src--|--com--|--wallace--|--AddAndSubtract.java
                            |--MultiplyAndDivide.java
                            |--Student.java
                |--junit--  |--AddAndSubtract.java
                            |--MultiplyAndDivide.java
                            |--Student.java
|--lib--|--junit.jar
|--build.xml
在使用ant构建build.xml时,总是提示:Could not find com.test.testAddAndSubtract. Make sure you have it in your classpath,不知错误出现在哪,麻烦帮忙看下
页: [1]
查看完整版本: 求助:ant执行单元测试的问题