简体   繁体   English

maven没有将test / java类编译到目标文件夹中

[英]maven is not compiling test/java classes into target folder

I tried cleaning my project through maven->clean and project->clean but it didnot work. 我尝试通过maven-> clean和project-> clean清理我的项目,但是没有用。 I tried changing my output folders explicitly under build path but not sure what to select for src/test/java 我尝试在构建路径下显式更改输出文件夹,但不确定为src / test / java选择什么

I also updated my testng plugin in pom.xml 我还更新了pom.xml中的testng插件

pom.xml pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd" >
  <modelVersion>4.0.0</modelVersion>
  <groupId>abc</groupId>
  <artifactId>xyz</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <description>Test</description>
  <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.11</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>21.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>3.3.1</version>
        </dependency>


    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-chrome-driver</artifactId>
         <version>3.3.1</version>
    </dependency>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-ie-driver -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-ie-driver</artifactId>
        <version>3.3.1</version>
    </dependency>

        <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.16</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.16</version>
    </dependency>

        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
        </dependency>


        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.37</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
            <!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->
        <dependency>
             <groupId>com.relevantcodes</groupId>
             <artifactId>extentreports</artifactId>
            <version>2.41.0</version>
        </dependency>


        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>3.1.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->

    </dependencies>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

  <build>

   <resources>
     <resource>
       <directory>src/test/resources</directory>
       <filtering>false</filtering>
       <includes>
          <include>**/*.properties</include>

        </includes>
     </resource>
   </resources>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>

                <source>1.8</source>
                <target>1.8</target>

            </configuration>
        </plugin>
    </plugins>

  </build>
</project>

Output folders for src/test/java and src/test/resources is /target/classes src / test / java和src / test / resources的输出文件夹是/ target / classes

and I am getting TestNG class not found in classpath error : 我正在类路径错误中找不到TestNG类:

org.testng.TestNGException: 
Cannot find class in classpath: testclass file

Earlier this code was working fine. 之前的这段代码运行良好。 I just tried refractoring the project by changing artifact id of maven project and from then not able to proceed. 我只是尝试通过更改Maven项目的工件ID来使项目屈服,但此后无法继续进行。

You need to add maven surefire plugin to run testNG classes. 您需要添加maven surefire 插件来运行testNG类。 It's a miracle if you were able to run the tests earlier without this plugin. 如果您能够在没有此插件的情况下更早地运行测试,那将是一个奇迹。 You have to add below plugin in the build phase to get going. 您必须在构建阶段添加以下插件才能开始。

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.20.1</version>
    <configuration>
      <includes>
        <include>Sample.java</include>
      </includes>
    </configuration>
  </plugin>

If you don't want to include the tests manually then by default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns: 如果您不想手动包含测试,则默认情况下,Surefire插件将自动包含具有以下通配符模式的所有测试类:

"**/Test*.java"

"**/*Test.java"

"**/*Tests.java"

"**/*TestCase.java"

Not sure how widely this applies, but I had success with this: 不知道这适用范围如何,但是我在此方面取得了成功:

Right click > Java build path > Source Make sure Include:(All) and Exclude:(None) is checked for all 4 folders 右键单击> Java构建路径>源确保对所有4个文件夹都都选中Include:(All)和Exclude:(None)

src/main/java src / main / java

src/main/resources src / main / resources

src/test/java src /测试/ java

src/test/resources src / test / resources

我认为您必须将非Maven项目转换为Maven项目

right click on project->Configure->Convert it to Maven

The issue for me was that the "Skip Tests" checkbox was checked. 对我来说,问题是已选中“跳过测试”复选框。

RClick project -> Run As -> Run Configurations -> Maven Build (select your build configuration) -> Uncheck Skip Tests checkbox RClick项目->运行方式->运行配置-> Maven构建(选择您的构建配置)->取消选中跳过测试复选框

This checkbox prevents Maven from compiling tests 此复选框阻止Maven编译测试

If you want to compile the tests, but don't want to execute them during build process, add -DskipTests in Goals 如果要编译测试,但不想在构建过程中执行测试,请在目标中添加-DskipTests

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未编译“目标”文件夹中生成的Maven Java类 - Maven java classes generated in “target” folder are not compiled 使用 maven exec-maven-plugin “target”文件夹生成的 Java 类不会被编译 - Java classes generated using maven exec-maven-plugin “target” folder are not compiled Maven:“目标”文件夹下缺少已编译的类 - Maven: Missed compiled classes under 'target' folder Eclipse + Maven和隐藏的$ {basedir} / target / classes文件夹? - Eclipse + Maven and hidden ${basedir}/target/classes folder? maven项目目录结构中目标中的classes文件夹 - classes folder in target in maven project directory structure gRPC maven 未在目标文件夹中生成存根类 - gRPC maven is not generating stub classes in the target folder 默认情况下,Maven不会将src / test / java中的* .xml文件复制到target / test-classes - Maven is not copying *.xml files in src/test/java to target/test-classes by default 如何防止 Maven 编译 src/test/java 中的类,这些类是在 generate-sources 阶段生成的? - How to prevent Maven from compiling classes in src/test/java, which are generated during the generate-sources phase? java-maven2:如何在pom中包含一个jar作为依赖,这样我就可以访问src / test / java文件夹中的测试类或类 - java-maven2: How to include the a jar as depedency in pom so that I will be able to access test classes or classes in src/test/java folder Maven:编译时将可执行文件(.exe)移动到目标文件夹 - Maven: Move Executable (.exe) into target Folder when Compiling
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM