我试图从命令提示符运行 testng.xml 但无法找出以下错误:
错误:无法找到或加载主类 org.testng.TestNG
或
错误:无法找到或加载主类 java。
同时使用两种不同的方法。
请提供一个突出的方法来做同样的事情。
我试图从命令提示符运行 testng.xml 但无法找出以下错误:
错误:无法找到或加载主类 org.testng.TestNG
或
错误:无法找到或加载主类 java。
同时使用两种不同的方法。
请提供一个突出的方法来做同样的事情。
谢谢大家,但我已经使用 Apache ant 解决了这个问题。
通过使用以下 - build.xml
<project name="name" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<!-- set global properties for build -->
<property name="basedir" value="." />
<property name="lib" value="${basedir}/lib" />
<property name="src" value="${basedir}/src" />
<property name="bin" value="${basedir}/bin" />
<property name="report-dir" value="${basedir}/Test-Report" />
<property name="testng-report-dir" value="${report-dir}/TestNGreport" />
<!-- ====== Set the classpath ==== -->
<path id="classpath">
<pathelement location="${bin}" />
<fileset dir="${lib}">
<include name="*.jar" />
</fileset>
</path>
<!-- Delete directories -->
<target name="delete-dir">
<delete dir="${bin}" />
<delete dir="${report-dir}" />
</target>
<!-- Creating directories -->
<target name="create" depends="delete-dir">
<mkdir dir="${bin}" />
<mkdir dir="${report-dir}" />
</target>
<!-- Compile the java code from ${src} into ${bin} -->
<target name="compile" depends="create">
<javac srcdir="${src}" classpathref="classpath" includeAntRuntime="No" destdir="${bin}" />
<echo> /* Compiled Directory Classes */ </echo>
</target>
<!-- Runs the file and generates Reportng report for TestNG-->
<taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="classpath" />
<target name="testng-execution" depends="compile">
<mkdir dir="${testng-report-dir}" />
<testng outputdir="${testng-report-dir}" classpathref="classpath" useDefaultListeners="true">
<xmlfileset dir="${basedir}" includes="testng.xml" />
</testng>
</target>
</project>
然后在命令提示符下输入:ant testng-execution
尝试通过 cmd 提示符运行,如下所示:
1. Go to project folder
2. Then: `java -cp [projectpath]\lib\*;[projectpath]\target org.testng.TestNG testng.xml`
路径:
在类 Unix 系统下使用分隔,而不是;
在 Windows 中:
java -cp ./src/lib/*:./bin org.testng.TestNG testng.xml
如果你在 Windows 下使用 bash,你应该使用;
,其他地方使用:
.
该;
字符表示 Unix shell 的语句结束,因此您可能尝试执行的是:
java -cp ./src/lib/*
./bin org.testng.TestNG testng.xml
我在windows上使用testNg,在windows命令提示符下执行,我使用命令:java -cp bin;libs/* org.testng.TestNG testng.xml
结果:试运行成功
总是在 Windows 上:我使用 git bash 命令,该命令没有成功执行