Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven 如何使用pom分离JUnit测试和Selenium测试_Maven_Selenium_Junit_Pom.xml - Fatal编程技术网

Maven 如何使用pom分离JUnit测试和Selenium测试

Maven 如何使用pom分离JUnit测试和Selenium测试,maven,selenium,junit,pom.xml,Maven,Selenium,Junit,Pom.xml,我有一个pom.xml,它粘贴在下面,我想知道如何修改它,使其可以说“mvn unittest”或“mvn seleniumtest”,以便能够分别运行这两种类型的测试。现在作为POM,如果我说“mvn测试”,它会在我的项目中运行以“测试”结尾的测试,但我无法理解在POM中这是在哪里定义的,以及如何定义的 pom: <?xml version="1.0"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi

我有一个pom.xml,它粘贴在下面,我想知道如何修改它,使其可以说“mvn unittest”或“mvn seleniumtest”,以便能够分别运行这两种类型的测试。现在作为POM,如果我说“mvn测试”,它会在我的项目中运行以“测试”结尾的测试,但我无法理解在POM中这是在哪里定义的,以及如何定义的

pom:

<?xml version="1.0"?>
<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>com.magnus.unittest</groupId>
  <artifactId>unittestproject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.9</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>2.6.0</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <build>
    <sourceDirectory>C:\enhetstesting\unittestproject\src\main\java</sourceDirectory>
    <scriptSourceDirectory>C:\enhetstesting\unittestproject\src\main\scripts</scriptSourceDirectory>
    <testSourceDirectory>C:\enhetstesting\unittestproject\src\test\java</testSourceDirectory>
    <outputDirectory>C:\enhetstesting\unittestproject\target\classes</outputDirectory>
    <testOutputDirectory>C:\enhetstesting\unittestproject\target\test-classes</testOutputDirectory>
    <resources>
      <resource>
        <directory>C:\enhetstesting\unittestproject\src\main\resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>C:\enhetstesting\unittestproject\src\test\resources</directory>
      </testResource>
    </testResources>
    <directory>C:\enhetstesting\unittestproject\target</directory>
    <finalName>unittestproject-0.0.1-SNAPSHOT</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.4.1</version>
        <executions>
          <execution>
            <id>default-clean</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.3.1</version>
        <executions>
          <execution>
            <id>default-install</id>
            <phase>install</phase>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <id>default-resources</id>
            <phase>process-resources</phase>
            <goals>
              <goal>resources</goal>
            </goals>
          </execution>
          <execution>
            <id>default-testResources</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.10</version>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <executions>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
          </execution>
          <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
        <executions>
          <execution>
            <id>default-jar</id>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>default-deploy</id>
            <phase>deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.0</version>
        <executions>
          <execution>
            <id>default-site</id>
            <phase>site</phase>
            <goals>
              <goal>site</goal>
            </goals>
            <configuration>
              <outputDirectory>C:\enhetstesting\unittestproject\target\site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
          <execution>
            <id>default-deploy</id>
            <phase>site-deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <outputDirectory>C:\enhetstesting\unittestproject\target\site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <outputDirectory>C:\enhetstesting\unittestproject\target\site</outputDirectory>
          <reportPlugins>
            <reportPlugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-project-info-reports-plugin</artifactId>
            </reportPlugin>
          </reportPlugins>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <outputDirectory>C:\enhetstesting\unittestproject\target\site</outputDirectory>
  </reporting>
</project>

4.0.0
com.magnus.unittest
单元测试项目
0.0.1-快照
朱尼特
朱尼特
4.9
测试
org.seleniumhq.selenium
硒爪哇
2.6.0
编译
假的
中心的
中央知识库
http://repo.maven.apache.org/maven2
从未
假的
中心的
中央知识库
http://repo.maven.apache.org/maven2
C:\enhetstesting\unittestproject\src\main\java
C:\enhetstesting\unittestproject\src\main\scripts
C:\enhetstesting\unittestproject\src\test\java
C:\enhetstesting\unittestproject\target\classes
C:\enhetstesting\unittestproject\target\testclasses
C:\enhetstesting\unittestproject\src\main\resources
C:\enhetstesting\unittestproject\src\test\resources
C:\enhetstesting\unittestproject\target
unittestproject-0.0.1-SNAPSHOT
maven antrun插件
1.3
maven汇编插件
2.2-β-5
maven依赖插件
2.1
maven发布插件
2
maven清洁插件
2.4.1
默认清除
清洁的
清洁的
maven安装插件
2.3.1
默认安装
安装
安装
maven资源插件
2.5
默认资源
过程资源
资源
默认测试资源
过程测试资源
测试资源
maven surefire插件
2.10
默认测试
测试
测试
maven编译器插件
2.3.2
默认测试编译
测试编译
测试编译
默认编译
编译
编译
maven jar插件
2.3.2
默认jar
包裹
罐子
maven部署插件
2.7
默认部署
部署
部署
maven站点插件
3
默认站点
网站
网站
C:\enhetstesting\unittestproject\target\site
org.apache.maven.plugins
maven项目信息报告插件
默认部署
站点部署
部署
C:\enhetstesting\unittestproject\target\site
org.apache.maven.plugins
maven项目信息报告插件
C:\enhetstesting\unittestproject\target\site
org.apache.maven.plugins
maven项目信息报告插件
C:\enhetstesting\unittestproject\target\site

您可以通过配置文件来实现这一点。Maven官方网站上有文档,但我喜欢Sonatype的免费在线书籍:

您将需要这样的内容()

通过下面的配置,您可以运行
mvn-test-Pjava-tests
mvn-Psel-tests
(例如,您有几个配置文件激活选项)


java测试
org.apache.maven.plugins
maven surefire插件
路径/到/选择/测试/**
sel测试
org.apache.maven.plugins
maven surefire插件
路径/到/选择/测试/**
请注意,这是一个很大的话题,上面的答案是让你走上正确的轨道。如果您有后续问题,请考虑将其作为新问题打开。祝你好运

<profiles>
  <profile>
    <id>java-tests</id>
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <excludes>
              <exclude>path/to/selinum/tests/**</exclude>
            </excludes>
          </configuration>
        </plugin>
      </plugins>
    </build>
  </profile>
  <profile>
    <id>sel-tests</id>
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <includes>
              <include>path/to/selinum/tests/**</include>
            </includes>
          </configuration>
        </plugin>
      </plugins>
    </build>
  </profile>
</profiles>