コマンドプロンプトからtestng.xmlを実行しようとしましたが、次のエラーを把握できませんでした。
エラー:メインクラスorg.testng.TestNGが見つかりませんでした。
またはどちらか
エラー:メインクラスjavaを検索またはロードできませんでした。
2つの異なる方法を使用しているとき。
同じことを行うための顕著な方法を提供してください。
回答:
回答№1は0どうもありがとう、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 コマンドプロンプトで
回答№2の場合は0
パスは、 :
Unixのようなシステムではなく ;
Windowsの場合:
java -cp ./src/lib/*:./bin org.testng.TestNG testng.xml
Windowsでbashを使用している場合は、使用する必要があります ;
その他の場所での使用 :
.
ザ ;
文字はUnixシェルのステートメントの終わりを意味するため、おそらく実行しようとしているのは次のとおりです。
java -cp ./src/lib/*
./bin org.testng.TestNG testng.xml
回答№3の場合は0
私はWindowsでtestNgを使用し、windowsコマンドプロンプトで実行し、コマンドを使用します:java -cp bin; libs / * org.testng.TestNG testng.xml
結果:テストは正常に実行されました
常にWindows:git bashコマンドを使用しますが、コマンドが正常に実行されません