You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Pablo <pa...@tiger.com.pl> on 2006/03/31 09:40:18 UTC

tests in a JAR file and surefire

Hello everyone

Is it possible to run tests using maven-surefire-plugin when the tests 
are in a JAR file ?
I can see that SurefirePlugin uses 
org.apache.maven.surefire.battery.DirectoryBattery exclusively and 
presume that it's not possible to use tests in JAR.
DirectoryBattery uses DirectoryScanner which checks if the baseDir is a 
directory. If not it throws an Exception.

However in the page: 
http://maven.apache.org/guides/mini/guide-attached-tests.html
there's written that it's possible to reuse tests using tests-jar.

Can someone tell me what it is meant for and how it can be used in 
surefire plugin?

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>com.myco.app</groupId>
      <artifactId>foo</artifactId>
      <version>1.0-SNAPSHOT</version>
      <type>test-jar</type>
    </dependency>
  </depdendnecies>
  ...
</project>


Cheers
Pablo

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


Re: tests in a JAR file and surefire

Posted by Gordon Henriksen <go...@mac.com>.
On Mar 31, 2006, at 05:57, Tomasz Pik wrote:

> On 3/31/06, Carlos Sanchez <ca...@apache.org> wrote:
>
>> It means that test can be reused in other projects, so you can  
>> extend or use them from the tests in that project. What is the  
>> point of runing the same tests again in another project?
>
> For example when you want to test some implementations of given  
> API. And tests 'bootstraps' implementation using some properties.  
> Something like TCK for JAXP implementation for example, with tests  
> starting with - 
> Djavax.xml.parsers.DocumentBuilderFactory=my.jaxp.impl.DBF (I've  
> never seen a TCK for JAXP but I can imagine that such approach for  
> testing implementations makes sense).

I can second the usefulness of this. Conformance tests in base  
classes are a very useful feature. I implemented these in a C# test  
harness at one point; the initial implementation was simply running  
all Test-annotated methods in non-abstract classes, regardless of  
whether the test methods were inherited or declared there. When I  
moved the unit tests to separate test assemblies, the pattern  
changed: Instead, a base class would come with an abstract test case:

/* base.dll */
abstract public class Base {
     abstract public object Memento { get; set; }
     abstract public bool SharesMemento(Base b);
}

/* base_t.dll */
abstract public class BaseTest {
     abstract protected Base CreateBase();
     [Test] public void TestMemento() {
         Base one = CreateBase();
         Base two = CreateBase();
         two.Memento = one.Memento;
         AssertTrue(one.SharesMemento(two));
         AssertTrue(two.SharesMemento(one));
     }
}

And the subclass would also author a derived test case:

/* sub.dll */
abstract public class Sub : Base {
     static counter = 0;
     int token = counter++;
     override public object Memento {
         get { return (object) token; }
         set { i = (int) token; }
     }
     override public bool SharesMemento(Base b) {
         return b is Sub && ((Sub) b).token == this.token;
     }
}

/* sub_t.dll */
abstract public class SubTest : BaseTest {
     abstract protected Base CreateBase() { return new Sub(); }
}

Might a similar pattern work with surefire?

     base/
        src/test/java/com/example/Base.java
     base-conformance-suite/ { depends: main }
        src/test/java/com/example/BaseConformanceTest.java
     sub/ { depends: base, base-conformance { scope: test } }
        src/main/java/com/example/Sub.java { extends: Base }
        src/test/java/com/example/SubTest.java { extends:  
BaseConformanceTest }

I'm not sure if surefire will find the inherited test methods, though.

Very excited about the TestNG support in surefire 2, BTW. Also, war  
merging will find use very swiftly indeed.

— G


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


Re: tests in a JAR file and surefire

Posted by Tomasz Pik <to...@gmail.com>.
On 3/31/06, Carlos Sanchez <ca...@apache.org> wrote:
> It means that test can be reused in other projects, so you can extend
> or use them from the tests in that project. What is the point of
> runing the same tests again in another project?

For example when you want to test some implementations of given API.
And tests 'bootstraps' implementation using some properties.
Something like TCK for JAXP implementation for example, with tests
starting with -Djavax.xml.parsers.DocumentBuilderFactory=my.jaxp.impl.DBF
(I've never seen a TCK for JAXP but I can imagine that such approach
for testing implementations makes sense).

Regards,
Tomek

> On 3/31/06, Pablo <pa...@tiger.com.pl> wrote:
> > Hello everyone
> >
> > Is it possible to run tests using maven-surefire-plugin when the tests
> > are in a JAR file ?
> > I can see that SurefirePlugin uses
> > org.apache.maven.surefire.battery.DirectoryBattery exclusively and
> > presume that it's not possible to use tests in JAR.
> > DirectoryBattery uses DirectoryScanner which checks if the baseDir is a
> > directory. If not it throws an Exception.
> >
> > However in the page:
> > http://maven.apache.org/guides/mini/guide-attached-tests.html
> > there's written that it's possible to reuse tests using tests-jar.
> >
> > Can someone tell me what it is meant for and how it can be used in
> > surefire plugin?
> >
> > <project>
> >   ...
> >   <dependencies>
> >     <dependency>
> >       <groupId>com.myco.app</groupId>
> >       <artifactId>foo</artifactId>
> >       <version>1.0-SNAPSHOT</version>
> >       <type>test-jar</type>
> >     </dependency>
> >   </depdendnecies>
> >   ...
> > </project>
> >
> >
> > Cheers
> > Pablo
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> > For additional commands, e-mail: dev-help@maven.apache.org
> >
> >
>
>
> --
> I could give you my word as a Spaniard.
> No good. I've known too many Spaniards.
>                              -- The Princess Bride
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

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


Re: tests in a JAR file and surefire

Posted by Carlos Sanchez <ca...@apache.org>.
It means that test can be reused in other projects, so you can extend
or use them from the tests in that project. What is the point of
runing the same tests again in another project?

On 3/31/06, Pablo <pa...@tiger.com.pl> wrote:
> Hello everyone
>
> Is it possible to run tests using maven-surefire-plugin when the tests
> are in a JAR file ?
> I can see that SurefirePlugin uses
> org.apache.maven.surefire.battery.DirectoryBattery exclusively and
> presume that it's not possible to use tests in JAR.
> DirectoryBattery uses DirectoryScanner which checks if the baseDir is a
> directory. If not it throws an Exception.
>
> However in the page:
> http://maven.apache.org/guides/mini/guide-attached-tests.html
> there's written that it's possible to reuse tests using tests-jar.
>
> Can someone tell me what it is meant for and how it can be used in
> surefire plugin?
>
> <project>
>   ...
>   <dependencies>
>     <dependency>
>       <groupId>com.myco.app</groupId>
>       <artifactId>foo</artifactId>
>       <version>1.0-SNAPSHOT</version>
>       <type>test-jar</type>
>     </dependency>
>   </depdendnecies>
>   ...
> </project>
>
>
> Cheers
> Pablo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>


--
I could give you my word as a Spaniard.
No good. I've known too many Spaniards.
                             -- The Princess Bride

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