我有一个简单的项目,我正在尝试使用Ant构建。我的项目包含testng,但我在尝试运行构建时收到一条错误消息。你能帮帮我吗?我花了很多时间试图找出问题所在,但到目前为止还没有任何结果。
下面是这个项目:
package selenium;
import org.testng.annotations.Test;
public class HomePage {
@Test
public void test(){
System.out.println("this is test");
}
}现在,我有了一个包含testng.jar的lib文件,还有一个运行该类的test.xml套件,下面是我的构建文件:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Concep.TestAutomation" basedir="." default="all">
<property name="src.dir" value="${basedir}/src" />
<property name="build.dir" value="target" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="suites.dir" value="suites" />
<property name="testng.path" value="lib/testng.jar" />
<property name="testreport.dir" value="${build.dir}/test-output" />
<target name="clean" description="Delete the build directory.">
<delete dir="${build.dir}" />
</target>
<target name="init" depends="clean" description="Create build directories.">
<!--Create the build directory structure used by compile -->
<mkdir dir="${build.dir}" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${testreport.dir}" />
</target>
<target name="compile" depends="init" description="Compile tests.">
<!-- Compile the java code from ${src} into ${classes.dir} -->
<javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true" />
</target>
<target name="run-test" depends="compile" description="Run test suite.">
<!-- Run a testng suite-->
<taskdef resource="testngtasks" classpath="${testng.path}" />
<testng classpathref="${testng.path}" outputDir="${testreport.dir}" haltonfailure="true" verbose="5">
<xmlfileset dir="${suites.dir}" includes="IA-smoke-test.xml" />
</testng>
</target>
<target name="all" depends="run-test" description="Executes all targets." />
<target name="all-debug" description="outputs all vars in use.">
<!-- useful to diagnose runtime problems -->
<echo message="'work.dir' = '${basedir}/..'"/>
<echo message="'lib.dir' = '${basedir}/lib'"/>
<echo message="'src.dir' = '${basedir}/src'"/>
<echo message="'config.dir' = '${basedir}/config'"/>
<echo message="'build.dir' = 'target'"/>
<echo message="'classes.dir' = '${build.dir}/classes'"/>
<echo message="'suites.dir' = '${basedir}/suites'"/>
<echo message="'testng.path' = '${basedir}/lib/testng.jar'"/>
</target>
</project>
发布于 2015-09-25 15:19:41
所以我在这里修复了这个问题,在编译目标上缺少了一个属性,它是"classpathref",从那里项目可以看到编译它所需的所有库,如果没有"classpathref“,项目看不到任何外部系统,所以我做了以下修复,
<path id="build.classpath">
<fileset dir="${lib.dir}" includes="**/*.jar" />
<fileset dir="${src.dir}/concep/selenium/core" includes="**/*.java" />
</path>
在我的compile目标中,我添加了以下属性
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="build.classpath" debug="true" includeantruntime="false"/>
发布于 2017-02-10 17:56:02
甚至我也曾面对过这个问题,并得到了同样的解决方案。
在您的pom.xml文件中,删除作用域,这应该可以很好地工作。
按照pom.xml中的以下代码,删除作用域标记。
尽管我们已经为Testng导入了maven依赖项,但当您在XML文件中添加scope标记时,它会被视为JUnit注释,而不是Testng。因此,当我删除作用域标记时,我的@Test Annotation被视为Testng Annotation。
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
**<scope>test</scope>** //Remove this line and compile maven
</dependency>https://stackoverflow.com/questions/32697906
复制相似问题