You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by PAN QIANHONG <pa...@hotmail.com> on 2013/04/12 19:53:51 UTC

Copy files for each test using surefire plugin



Hi,

I am new to Maven, I am working on converting the unit tests from Ant build to Maven build. I have a basic question for surefire plugin and hope someone on this list can help. Thanks in advance.

In Ant build xml file, we need to copy a property file to a /tmp directory before each test, something like this:

<target name="test-properties">
  <copy file="properties.data" tofile=“/tmp/properties.data" overwrite="true" />
  <junit>
    <test name="TestProperties"/>
  </junit>
  <copy file="properties.data" tofile=“/tmp/properties.data" overwrite="true" />
  <junit>
    <test name="TestPropertiesAgain"/>
  </junit>

</target>

I am trying to use Maven to achieve this in <build><plugins> shown below. The first test seems work fine and updated /tmp/properties.data as expected. 

But the second test failed because the /tmp/properties.data is not overwritten by maven-resources-plugin. It still has the content from the last test run.

There is a warning saying from the output of "mvn clean test":

[WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-resources-plugin.

Is this the cause of the file not copied? How can I handle this case in Maven?

Thanks,
-- QH


           <!-- Copy config files to the work directory .-->
            <plugin>
              <artifactId>maven-resources-plugin</artifactId>
              <version>2.6</version>
              <executions>
                <execution>
                  <id>copy-resources</id>
                  <phase>process-test-resources</phase>
                  <goals>
                    <goal>copy-resources</goal>
                  </goals>
                  <configuration>
                    <overwrite>true</overwrite>
                    <outputDirectory>/tmp</outputDirectory>
                    <resources>
                      <resource>
                        <directory>src/test/resources</directory>
                        <includes>
                          <include>properties.data</include>
                        </includes>
                        <filtering>true</filtering>
                      </resource>
                    </resources>
                  </configuration>
                </execution>
              </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
                    <forkMode>always</forkMode>
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>testProperties</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                            <includes>
                                <include>**/TestProperties.java</include>
                            </includes>
                          </configuration>
                    </execution>
                  </executions>
              </plugin>


          <!-- Copy config files to the work directory 2nd time .-->

            <plugin>

              <artifactId>maven-resources-plugin</artifactId>

              <version>2.6</version>

              <executions>

                <execution>

                  <id>copy-resources-again</id>

                  <phase>process-test-resources</phase>

                  <goals>

                    <goal>copy-resources</goal>

                  </goals>

                  <configuration>

                    <overwrite>true</overwrite>

                    <outputDirectory>/tmp</outputDirectory>

                    <resources>

                      <resource>

                        <directory>src/test/resources</directory>

                        <includes>

                          <include>properties.data</include>

                        </includes>

                        <filtering>true</filtering>

                      </resource>

                    </resources>

                  </configuration>

                </execution>

              </executions>

            </plugin>



            <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-surefire-plugin</artifactId>

                <configuration>

                    <testFailureIgnore>true</testFailureIgnore>

                    <redirectTestOutputToFile>true</redirectTestOutputToFile>

                    <forkMode>always</forkMode>

                    <skip>true</skip>

                </configuration>

                <executions>

                    <execution>

                        <id>testPropertiesAgain</id>

                        <goals>

                            <goal>test</goal>

                        </goals>

                        <configuration>

                            <skip>false</skip>

                            <includes>

                                <include>**/TestPropertiesAgain.java</include>

                            </includes>

                          </configuration>

                    </execution>

                  </executions>

              </plugin>








 		 	   		  

Re: Copy files for each test using surefire plugin

Posted by Wayne Fay <wa...@gmail.com>.
> [WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-resources-plugin.

This appears because you should use multiple entries under
<executions> with unique ids and only mention each plugin once in the
pom file.

> Is this the cause of the file not copied? How can I handle this case in Maven?

Dunno. Agree with Kristian on @Before.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Copy files for each test using surefire plugin

Posted by Kristian Rosenvold <kr...@gmail.com>.
I think you should use a @Before or a @BeforeClass method in your
tests to do this.


Kristian

2013/4/12 PAN QIANHONG <pa...@hotmail.com>:
>
>
>
> Hi,
>
> I am new to Maven, I am working on converting the unit tests from Ant build to Maven build. I have a basic question for surefire plugin and hope someone on this list can help. Thanks in advance.
>
> In Ant build xml file, we need to copy a property file to a /tmp directory before each test, something like this:
>
> <target name="test-properties">
>   <copy file="properties.data" tofile=“/tmp/properties.data" overwrite="true" />
>   <junit>
>     <test name="TestProperties"/>
>   </junit>
>   <copy file="properties.data" tofile=“/tmp/properties.data" overwrite="true" />
>   <junit>
>     <test name="TestPropertiesAgain"/>
>   </junit>
>
> </target>
>
> I am trying to use Maven to achieve this in <build><plugins> shown below. The first test seems work fine and updated /tmp/properties.data as expected.
>
> But the second test failed because the /tmp/properties.data is not overwritten by maven-resources-plugin. It still has the content from the last test run.
>
> There is a warning saying from the output of "mvn clean test":
>
> [WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-resources-plugin.
>
> Is this the cause of the file not copied? How can I handle this case in Maven?
>
> Thanks,
> -- QH
>
>
>            <!-- Copy config files to the work directory .-->
>             <plugin>
>               <artifactId>maven-resources-plugin</artifactId>
>               <version>2.6</version>
>               <executions>
>                 <execution>
>                   <id>copy-resources</id>
>                   <phase>process-test-resources</phase>
>                   <goals>
>                     <goal>copy-resources</goal>
>                   </goals>
>                   <configuration>
>                     <overwrite>true</overwrite>
>                     <outputDirectory>/tmp</outputDirectory>
>                     <resources>
>                       <resource>
>                         <directory>src/test/resources</directory>
>                         <includes>
>                           <include>properties.data</include>
>                         </includes>
>                         <filtering>true</filtering>
>                       </resource>
>                     </resources>
>                   </configuration>
>                 </execution>
>               </executions>
>             </plugin>
>
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-surefire-plugin</artifactId>
>                 <configuration>
>                     <testFailureIgnore>true</testFailureIgnore>
>                     <redirectTestOutputToFile>true</redirectTestOutputToFile>
>                     <forkMode>always</forkMode>
>                     <skip>true</skip>
>                 </configuration>
>                 <executions>
>                     <execution>
>                         <id>testProperties</id>
>                         <goals>
>                             <goal>test</goal>
>                         </goals>
>                         <configuration>
>                             <skip>false</skip>
>                             <includes>
>                                 <include>**/TestProperties.java</include>
>                             </includes>
>                           </configuration>
>                     </execution>
>                   </executions>
>               </plugin>
>
>
>           <!-- Copy config files to the work directory 2nd time .-->
>
>             <plugin>
>
>               <artifactId>maven-resources-plugin</artifactId>
>
>               <version>2.6</version>
>
>               <executions>
>
>                 <execution>
>
>                   <id>copy-resources-again</id>
>
>                   <phase>process-test-resources</phase>
>
>                   <goals>
>
>                     <goal>copy-resources</goal>
>
>                   </goals>
>
>                   <configuration>
>
>                     <overwrite>true</overwrite>
>
>                     <outputDirectory>/tmp</outputDirectory>
>
>                     <resources>
>
>                       <resource>
>
>                         <directory>src/test/resources</directory>
>
>                         <includes>
>
>                           <include>properties.data</include>
>
>                         </includes>
>
>                         <filtering>true</filtering>
>
>                       </resource>
>
>                     </resources>
>
>                   </configuration>
>
>                 </execution>
>
>               </executions>
>
>             </plugin>
>
>
>
>             <plugin>
>
>                 <groupId>org.apache.maven.plugins</groupId>
>
>                 <artifactId>maven-surefire-plugin</artifactId>
>
>                 <configuration>
>
>                     <testFailureIgnore>true</testFailureIgnore>
>
>                     <redirectTestOutputToFile>true</redirectTestOutputToFile>
>
>                     <forkMode>always</forkMode>
>
>                     <skip>true</skip>
>
>                 </configuration>
>
>                 <executions>
>
>                     <execution>
>
>                         <id>testPropertiesAgain</id>
>
>                         <goals>
>
>                             <goal>test</goal>
>
>                         </goals>
>
>                         <configuration>
>
>                             <skip>false</skip>
>
>                             <includes>
>
>                                 <include>**/TestPropertiesAgain.java</include>
>
>                             </includes>
>
>                           </configuration>
>
>                     </execution>
>
>                   </executions>
>
>               </plugin>
>
>
>
>
>
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org