如何在Ant中运行JUnit测试套件?

时间:2013-11-27 17:16:44

标签: ant junit selenium-webdriver

我有这样的junit测试套件用于硒测试:

@RunWith(Suite.class)
@SuiteClasses({ Test1.class, Test2.class})
 public class TestSuite {
 }

我想通过ant运行测试套装,所以我添加了这样的目标:

<property environment="environm"/>
<property name="ROOT_PATH" value="../../../../.."/>
<property name="ECLIPSE" value="${ROOT_PATH}/eclipse-kepler/eclipse"/>
<property name="junit" value="junit"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="JUnit.library>
    <pathelement location="${ECLIPSE}/plugins/org.junit_4.11.0.v201303080030/junit.jar"/>
    <pathelement location="${ECLIPSE}/plugins/org.hamcrest.core_1.3.0.v201303031735.jar"/>
</path>
<path id="Tests.classpath">
    <pathelement location="bin"/>
    <path refid="JUnit.library"/>
    <pathelement location="${ROOT_PATH}/selenium-server-standalone-2.37.0.jar"/>
</path>
<target name="TestSuite">
    <mkdir dir="${junit}"/>
    <junit fork="yes" printsummary="withOutAndErr">
        <sysproperty key="variable" value="${value}"/>
        <formatter type="xml"/>
        <batchtest todir="${junit}">
      <fileset dir="src">
             <include name="**/TestSuite.class"/>
          </fileset>
        </batchtest>
        <classpath refid="Tests.classpath"/>
    </junit>
</target>

我运行这样的命令:

ant build TestSuite -Dvariable="value"

但测试根本没有运行。这是输出:

C:\Selenium>ant build TestSuite -Dvariable="value"
Buildfile: C:\Selenium\build.xml

build-subprojects:

init:

build-project:
  [echo] Selenium: C:\Selenium\build.xml

build:

TestSuite:

BUILD SUCCESSFUL

我是蚂蚁的新手。我做错了什么?

1 个答案:

答案 0 :(得分:0)

定位类路径,如下所示

<target name="TestSuite">
<mkdir dir="${junit}"/>
<junit fork="yes" printsummary="withOutAndErr">
    <sysproperty key="variable" value="${value}"/>
    <formatter type="xml"/>

  <classpath refid="Tests.classpath"/>
    <batchtest todir="${junit}">
  <fileset dir="src">
         <include name="**/TestSuite.class"/>
      </fileset>
    </batchtest>

</junit>