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

时间:2017-11-30 15:50:45

标签: java eclipse maven

我尝试通过maven-> clean和project->清理我的项目但是它没有用。我尝试在构建路径下显式更改输出文件夹,但不确定要为src / test / java

选择什么

我还在pom.xml中更新了我的testng插件

的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>

src / test / java和src / test / resources的输出文件夹是/ target / classes

我在classpath错误中找不到TestNG类:

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

此前此代码工作正常。我只是尝试通过更改maven项目的工件ID来折射项目,然后无法继续。

4 个答案:

答案 0 :(得分:1)

您需要添加 maven surefire插件才能运行testNG类。如果你能够在没有这个插件的情况下运行测试,这是一个奇迹。你必须在构建阶段添加下面的插件才能开始。

  <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>

如果您不想手动包含测试,那么默认情况下,Surefire插件会自动包含具有以下通配符模式的所有测试类:

"**/Test*.java"

"**/*Test.java"

"**/*Tests.java"

"**/*TestCase.java"

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

不确定这有多广泛,但我成功了:

右键单击&gt; Java构建路径&gt;资源 确保选中包括:(全部)和排除:(无)检查所有4个文件夹

的src /主/ JAVA

的src /主/资源

的src /测试/ JAVA

的src /测试/资源

答案 3 :(得分:0)

对我来说,问题是已选中“跳过测试”复选框。

RClick项目->运行方式->运行配置-> Maven构建(选择构建配置)->取消选中“跳过测试”复选框

此复选框阻止Maven编译测试

如果您要编译测试,但又不想在构建过程中执行测试,请在目标中添加-DskipTests