gpt4 book ai didi

java - 来自 LeanFT 项目的 JAR 包

转载 作者:行者123 更新时间:2023-12-02 02:04:46 26 4
gpt4 key购买 nike

我在 IntelliJ IDEA 中有一个带有 TestNG 框架的 LeanFT 测试套件。我使用 mvn install 命令生成 jar 文件。当我尝试执行它时收到错误消息:

Error: Could not find or load main class test.LeanFTest

LeanFTest 类存在于测试命名包中,并包含以下行:

public class LeanFTest {
public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException {
TestNG testNG = new TestNG();
testNG.setTestSuites(Arrays.asList("testng.xml"));
testNG.setPreserveOrder(true);
testNG.run();
}

testng.xml 文件:

<suite name="MyTestSuite" verbose="2" parallel="methods" thread-count="1">

<listeners>
<listener class-name="utils.TestNGListener"></listener>
</listeners>

<test name="Regression" parallel="false" >
<classes>
<class name="test.RegressionTest" />
</classes>
</test>

</suite>

我在 pom.xml 中使用以下插件:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteIfNewer>true</overWriteIfNewer>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>test.LeanFTest</mainClass>
</manifest>
</archive>
<excludes>
<exclude>log4j2.xml</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/leanft-assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>

leanft- assembly.xml 文件:

<?xml version="1.0"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

<id>fat-tests</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>test</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.directory}/test-classes</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.class</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>

更新:我检查了 JAR 文件,发现它包含 /src/main/ 项目文件夹中的文件,但不包含 /src/test/ 文件夹,其中测试类是位于。

更新 06.27。我的项目结构与此示例项目相同:https://github.com/kohli-harshit/leanft-testng-template

最佳答案

LeanFTest 类 必须包含@Test 注释不是 Java main 方法。 TestNG 不会调用 java main 方法。因此,无论您要调用哪个类(RegressionTest),请确保它有@Test注释要调用。

您可以通过使用 TestNG Run 执行脚本来检查脚本,而无需从 .XML 文件执行。

关于java - 来自 LeanFT 项目的 JAR 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50983746/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com