You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Dmitry Beransky <dm...@gmail.com> on 2007/01/18 22:27:33 UTC

categorizing tests

Hi,

Just finished reading an article on test categorization:
<http://www-128.ibm.com/developerworks/java/library/j-cq10316/index.html?ca=drs->.
 Any recommendations how how to implement this in Maven?


Thanks
D.

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


Re: categorizing tests

Posted by Jiaqi Guo <cy...@gmail.com>.
Dmitry Beransky wrote:

> Ideally, I wish I could annotate tests with a type (e.g.
> @Test(type=component) public void testSomeFunction() {...}) and have
> the test framework pick the tests out for me.
>
> Lacking above, it's probably a good idea to break tests into multiple
> directories based on their type (could be a good idea regardless), and
> then simply modify test source directory based on the same system
> property your recommended:
>
> <build>
>   
> <testSourceDirectory>src/test/java/${test.category}</testSourceDirectory>
> </build>
>
> can I define a default value for ${test.category} in POM and then
> override it at runtime with -Dtest.category=<value>?
>
> or is profiles still a preferred way of approaching this and if so, why?
>
> thanks
> d.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Hi Dmitry,

If you want to categorize the tests with your own Annotation, you will 
definitely need to write you own plugin to run these test cases since 
sunfire-plugin has no knowledge of those Annotations. Then it would be 
problem to make plugins like clover to work with your own test plugin.

The testSourceDirectory is sort of coded in maven-model 
(http://svn.apache.org/repos/asf/maven/components/trunk/maven-model/maven.mdo), 
it could be a mess to change it and add multiple test source directories 
into POM model.

This left the "profile" the only option that I could come up with.

Even within a <profile>, you can't define a different 
testSourceDirectory according to 
http://maven.apache.org/guides/introduction/introduction-to-profiles.html. 
So I had to make the categorization base on file pattern.

In my example code, without specifying -Dtest.category, no profile will 
be activated, so the <build> directly under <project> will count in that 
case.



Best regards

-- 



Jiaqi Guo

http://www.cyclopsgroup.org
jiaqi.guo@gmail.com


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


Re: categorizing tests

Posted by Dmitry Beransky <dm...@gmail.com>.
On 1/18/07, Jiaqi Guo <cy...@gmail.com> wrote:
> Dmitry Beransky wrote:
> > Just finished reading an article on test categorization:
> > <http://www-128.ibm.com/developerworks/java/library/j-cq10316/index.html?ca=drs->.
> >
> > Any recommendations how how to implement this in Maven?
>
> Although I don't 100% percent agree with the article, I believe
> technically multiple test case file pattern can be defined for each
> sunfire-plugin in multiple profiles.

Thanks, that's an interesting idea and got me thinking...

Ideally, I wish I could annotate tests with a type (e.g.
@Test(type=component) public void testSomeFunction() {...}) and have
the test framework pick the tests out for me.

Lacking above, it's probably a good idea to break tests into multiple
directories based on their type (could be a good idea regardless), and
then simply modify test source directory based on the same system
property your recommended:

<build>
   <testSourceDirectory>src/test/java/${test.category}</testSourceDirectory>
</build>

can I define a default value for ${test.category} in POM and then
override it at runtime with -Dtest.category=<value>?

or is profiles still a preferred way of approaching this and if so, why?

thanks
d.

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


Re: categorizing tests

Posted by Jiaqi Guo <cy...@gmail.com>.
Dmitry Beransky wrote:
> Hi,
>
> Just finished reading an article on test categorization:
> <http://www-128.ibm.com/developerworks/java/library/j-cq10316/index.html?ca=drs->. 
>
> Any recommendations how how to implement this in Maven?
>
>
> Thanks
> D.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Although I don't 100% percent agree with the article, I believe 
technically multiple test case file pattern can be defined for each 
sunfire-plugin in multiple profiles. All test cases may still have to 
stay in one directory if you are OK to categorize them by name pattern 
or package.

http://maven.apache.org/guides/introduction/introduction-to-profiles.html

pom.xml could be something like

......
  <profiles>
    <profile>
      <id>test.category.component</id>
      <activation>
        <property>
          <name>test.category</name>
          <value>component</value>
        </property>
      </activation>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <includes>
              <include>**/*ComponentTest.java</include>
            </includes>
          </configuration>
        </plugin>
      </plugins>
    </profile>
    <profile>
      <id>test.category.system</id>
      <activation>
        <property>
          <name>test.category</name>
          <value>system</value>
        </property>
      </activation>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <includes>
              <include>**/*SystemTest.java</include>
            </includes>
          </configuration>
        </plugin>
      </plugins>
    </profile>
  </profiles>

... ...


By running "mvn test -Dtest.category=component", only *ComponentTest 
will be invoked. Hope it helps.



Regards

-- 

Jiaqi Guo
http://www.cyclopsgroup.org


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