I think you should use a @Before or a @BeforeClass method in your tests to do this.
Kristian 2013/4/12 PAN QIANHONG <[email protected]>: > > > > 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: [email protected] For additional commands, e-mail: [email protected]
