Assuming what I said earlier about excludes overriding includes, the most obvious way I can see you handling this would be with 2 profiles -- one that is active by default and excludes the test, and another that requires -P etc that includes the test. Then you wouldn't have any surefire declaration in the main pom, but instead 2 profiles that would each declare it independently with different configuration options.
Wayne On 11/12/07, Dan Kigelman <[EMAIL PROTECTED]> wrote: > Mm.. Is there any way to do what I'm trying though? Execute one or > more of the tests if and only if? Maybe by running on different > executions of surefire? > > I tried to attach a .zip of my test code, but the message was rejected > as spam. Here is the sample program as an in-text attachment. It was > generated with archetype:create and modified to show the problem. > > Thank you again for your help, > > -- Dan > . > |-- pom.xml > `-- src > |-- main > | `-- java > | `-- sample > | `-- test > | `-- App.java > `-- test > `-- java > `-- sample > `-- test > |-- ExecuteAlwaysTest.java > `-- ExecuteSometimesTest.java > > 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/maven-v4_0_0.xsd"> > <modelVersion>4.0.0</modelVersion> > <groupId>sample.test</groupId> > <artifactId>execute-test-conditionally</artifactId> > <packaging>jar</packaging> > <version>1.0-SNAPSHOT</version> > <name>execute-test-conditionally</name> > <url>http://maven.apache.org</url> > <dependencies> > <dependency> > <groupId>junit</groupId> > <artifactId>junit</artifactId> > <version>3.8.1</version> > <scope>test</scope> > </dependency> > </dependencies> > > <build> > <plugins> > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-surefire-plugin</artifactId> > <configuration> > <excludes> > <exclude>**/ExecuteSometimesTest.java</exclude> > </excludes> > </configuration> > </plugin> > </plugins> > </build> > > <profiles> > <profile> > <id>conditionProfile</id> > <activation> > <property> > <name>some_condition</name> > <value>true</value> > </property> > </activation> > <build> > <plugins> > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-surefire-plugin</artifactId> > <executions> > <execution> > <id>rareTest</id> > <goals> > <goal>test</goal> > </goals> > <phase>test</phase> > <configuration> > <includes> > <include>**/ExecuteSometimesTest.java</include> > </includes> > <excludes /> > </configuration> > </execution> > </executions> > </plugin> > </plugins> > </build> > </profile> > </profiles> > </project> > > App.java: (ignore me) > ------------------------------ > package sample.test; > > /** > * Hello world! > * > */ > public class App > { > public static void main( String[] args ) > { > System.out.println( "Hello World!" ); > } > } > > > ExecuteAlwaysTest.java: > ------------------------------------ > > package sample.test; > > import junit.framework.Test; > import junit.framework.TestCase; > import junit.framework.TestSuite; > > /** > * Unit test for simple App. > */ > public class ExecuteAlwaysTest > extends TestCase > { > /** > * Create the test case > * > * @param testName name of the test case > */ > public ExecuteAlwaysTest( String testName ) > { > super( testName ); > } > > /** > * Rigourous Test :-) > */ > public void testApp() > { > assertTrue( true ); > } > } > > ExecuteSometimesTest.java: > ------------------------------------------ > > package sample.test; > > import junit.framework.Test; > import junit.framework.TestCase; > import junit.framework.TestSuite; > > /** > * Unit test for simple App. > */ > public class ExecuteSometimesTest > extends TestCase > { > /** > * Create the test case > * > * @param testName name of the test case > */ > public ExecuteSometimesTest( String testName ) > { > super( testName ); > } > > /** > * Rigourous Test :-) > */ > public void testApp() > { > fail(); > } > } > > > On Nov 12, 2007 11:07 AM, Wayne Fay <[EMAIL PROTECTED]> wrote: > > Without looking at the code I can't be sure, but I would assume that > > you can't include -and- exclude the same file. Probably the exclude > > list is processed "last' in the code which means it won't run. > > > > > > Wayne > > > > On 11/11/07, Dan Kigelman <[EMAIL PROTECTED]> wrote: > > > Thank you Wayne, > > > > > > I will be careful about that. It seems it was working on my linux > laptop, > > > but I'm sure you've averted some of my future headaches for executing > this > > > on all kinds of shells. I renamed the profile and activation to the > > > following: > > > > > > <profile> > > > <id>conditionProfile</id> > > > <activation> > > > <property> > > > <name>some_condition</name> > > > <value>true</value> > > > </property> > > > </activation> > > > <build> > > > > > > I execute now with "mvn test -Dsome_condition=true" but still with the > same > > > result: > > > > > > ------------------------------------------------------- > > > T E S T S > > > ------------------------------------------------------- > > > Running sample.test.ExecuteAlwaysTest > > > Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.04 sec > > > > > > Results : > > > > > > Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 > > > > > > [INFO] [surefire:test {execution: rareTest}] > > > [INFO] Surefire report directory: > > > > /home/danik/workspace/test2/execute-test-conditionally/target/surefire-reports > > > > > > ------------------------------------------------------- > > > T E S T S > > > ------------------------------------------------------- > > > There are no tests to run. > > > > > > Results : > > > > > > Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 > > > > > > [INFO] > > > ------------------------------------------------------------------------ > > > [INFO] BUILD SUCCESSFUL > > > [INFO] > > > ------------------------------------------------------------------------ > > > > > > Somehow the second surefire execution includes no tests... > > > > > > -- Dan > > > > > > > > > On Nov 11, 2007 5:41 PM, Wayne Fay <[EMAIL PROTECTED]> wrote: > > > > > > > Try renaming the profile to some_condition, and then using > > > > -Dsome_condition=true. I've never tried to use a property named a-b-c > > > > and I'm not entirely sure how different operating systems pass that to > > > > Java and how it is interpreted prior to handing it to Maven (eg -D, -h > > > > etc). So I would just avoid -'s in profile names, personally. > > > > > > > > Wayne > > > > > > > > On 11/11/07, Dan Kigelman <[EMAIL PROTECTED]> wrote: > > > > > Hello! > > > > > > > > > > I am trying to execute a test if and only if a certain condition is > set > > > > > (such as a profile is activated). The test would fail if it is run > on > > > > some > > > > > systems, so I am trying to disable it by default, and run it only > when > > > > run > > > > > on the relevant system. > > > > > > > > > > I made a sample project to simplify the problem. Below is the > relevant > > > > part > > > > > my pom: > > > > > > > > > > <build> > > > > > <plugins> > > > > > <plugin> > > > > > <groupId>org.apache.maven.plugins</groupId> > > > > > <artifactId>maven-surefire-plugin</artifactId> > > > > > <configuration> > > > > > <excludes> > > > > > <exclude>**/ExecuteSometimesTest.java</exclude> > > > > > </excludes> > > > > > </configuration> > > > > > </plugin> > > > > > </plugins> > > > > > </build> > > > > > > > > > > <profiles> > > > > > <profile> > > > > > <id>condition-profile</id> > > > > > <activation> > > > > > <property> > > > > > <name>some-condition</name> > > > > > </property> > > > > > </activation> > > > > > <build> > > > > > <plugins> > > > > > <plugin> > > > > > <groupId>org.apache.maven.plugins</groupId> > > > > > <artifactId>maven-surefire-plugin</artifactId> > > > > > <executions> > > > > > <execution> > > > > > <id>rare-test</id> > > > > > <goals> > > > > > <goal>test</goal> > > > > > </goals> > > > > > <phase>test</phase> > > > > > <configuration> > > > > > <includes> > > > > > <include>**/ExecuteSometimesTest.java</include> > > > > > </includes> > > > > > <excludes /> > > > > > </configuration> > > > > > </execution> > > > > > </executions> > > > > > </plugin> > > > > > </plugins> > > > > > </build> > > > > > </profile> > > > > > </profiles> > > > > > > > > > > When I execute "mvn test" it works as expected: > > > > > ------------------------------------------------------- > > > > > T E S T S > > > > > ------------------------------------------------------- > > > > > Running sample.test.ExecuteAlwaysTest > > > > > Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: > 0.085sec > > > > > > > > > > Results : > > > > > > > > > > Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 > > > > > > > > > > [INFO] > > > > > > ------------------------------------------------------------------------ > > > > > [INFO] BUILD SUCCESSFUL > > > > > [INFO] > > > > > > ------------------------------------------------------------------------ > > > > > > > > > > > > > > > However, when I execute "mvn test -Dsome-condition" the > > > > > ExecuteSometimesTest.java is not executed: > > > > > > > > > > ------------------------------------------------------- > > > > > T E S T S > > > > > ------------------------------------------------------- > > > > > Running sample.test.ExecuteAlwaysTest > > > > > Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.04 > sec > > > > > > > > > > Results : > > > > > > > > > > Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 > > > > > > > > > > [INFO] [surefire:test {execution: rare-test}] > > > > > [INFO] Surefire report directory: > > > > > > > > > > > > > /home/danik/workspace/test2/execute-test-conditionally/target/surefire-reports > > > > > > > > > > ------------------------------------------------------- > > > > > T E S T S > > > > > ------------------------------------------------------- > > > > > There are no tests to run. > > > > > > > > > > Results : > > > > > > > > > > Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 > > > > > > > > > > [INFO] > > > > > > ------------------------------------------------------------------------ > > > > > [INFO] BUILD SUCCESSFUL > > > > > [INFO] > > > > > > ------------------------------------------------------------------------ > > > > > > > > > > Am I doing something wrong or is this a known problem? > > > > > > > > > > Help would be much appreciated!! > > > > > > > > > > -- Dan > > > > > > > > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
