2012-10-05 3 views
3

아래에 붙여 넣은 pom.xml이 있는데 "mvn unittest"또는 "mvn seleniumtest"라고 말할 수 있도록 어떻게 수정할 수 있는지 알고 싶습니다. 두 종류의 테스트를 분리하여 실행할 수 있어야합니다. 이제 POM이 "mvn test"라고 말하면 내 프로젝트에서 "Test"로 끝나는 테스트가 실행되지만 POM이 정의되고 어떻게되는지는 이해할 수 없습니다.POM을 사용하여 JUnit 테스트와 Selenium 테스트를 분리하는 방법

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> 

답변

8

당신은 프로파일이 작업을 수행 할 수 있습니다. 공식 메이븐 웹 사이트에는 문서가 있지만, 나는 Sonatype의 무료 온라인 서적을 좋아한다. Maven: The Complete Reference - 5.3. Profile Activation

다음과 같은 것이 필요하다 (see documentation on test exclusions).

아래 구성을 사용하여 mvn test -Pjava-tests 또는 mvn -Psel-tests을 실행할 수 있습니다 (예 : 프로필 활성화를위한 몇 가지 옵션이 있습니다).

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

위의 내용은 큰 문제이며 위의 답변은 올바른 길을 찾아드립니다. 후속 조치 사항이있는 경우 새로운 질문으로여십시오. 행운을 빕니다!

+0

감사합니다. Noahz, 할 일이있는 것처럼 보입니다. ;-) –

관련 문제