maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Kaplan <d...@mirthcorp.com>
Subject Re: Maven: How can I run/include a class in a jar with the failsafe plugin?
Date Fri, 18 Oct 2013 00:30:49 GMT
I've found an "ok" solution.  I just extend the class in the module I plan
to run the tests in and include the child.  It works the way I want.


On Thu, Oct 17, 2013 at 4:58 PM, Dan Kaplan <dank@mirthcorp.com> wrote:

> RunWith:
>
>  * When a class is annotated with <code>&#064;RunWith</code> or extends
a
> class annotated
>  * with <code>&#064;RunWith</code>, JUnit will invoke the class it
> references to run the
>  * tests in that class instead of the runner built into JUnit. We added
> this feature late
>  * in development. While it seems powerful we expect the runner API to
> change as we learn
>  * how people really use it. Some of the classes that are currently
> internal will likely
>  * be refined and become public.
>  *
>  * For example, suites in JUnit 4 are built using RunWith, and a custom
> runner named Suite
>
> AllTests:
>
> Runner for use with JUnit 3.8.x-style AllTests classes
>  * (those that only implement a static <code>suite()</code>
>  * method). For example:
>  * <pre>
>  * &#064;RunWith(AllTests.class)
>  * public class ProductTests {
>  *    public static junit.framework.Test suite() {
>  *       ...
>  *    }
>  * }
>
> So this class will use AllTests as a runner.  All tests will call the
> suite() method on this class.  The suite() method collects integration
> tests from the classpath and runs them.  I'm sorry I'm not answering
> directly, but I can't because I don't know what terminology to use.  I'll
> show you some of the code:
>
> @RunWith(AllTests.class)
> public class DistributedIntegrationTestRunner {
>
>     private static Logger log =
> LoggerFactory.getLogger(DistributedIntegrationTestRunner.class);
>
>     public static TestSuite suite() {
>         TestSuite suite = new TestSuite();
>
>         ClassesFinder classesFinder = new
> ClasspathFinderFactory().create(true,
>                 new String[]{".*IntegrationTest.*"},
>                 new SuiteType[]{SuiteType.TEST_CLASSES},
>                 new Class[]{Object.class},
>                 new Class[]{},
>                 "java.class.path");
>
>         int nodeNumber = systemPropertyInteger("node.number", "0");
>         int totalNodes = systemPropertyInteger("total.nodes", "1");
>
>         List<Class<?>> allTestsSorted = getAllTestsSorted(classesFinder);
>         allTestsSorted = filterIgnoredTests(allTestsSorted);
>         List<Class<?>> myTests = getMyTests(allTestsSorted, nodeNumber,
> totalNodes);
>         log.info("There are " + allTestsSorted.size() + " tests to choose
> from and I'm going to run " + myTests.size() + " of them.");
>         for (Class<?> myTest : myTests) {
>             log.info("I will run " + myTest.getName());
>             suite.addTest(new JUnit4TestAdapter(myTest));
>         }
>
>         return suite;
>     }
>
>
> None of my tests use the @RunWith annotation, only this class does.  I
> don't think I can add that to the tests because DistributedIntegrationTestRunner
> does not implement Runner so the code won't compile if I put
> @RunWith(DistributedIntegrationTestRunner.class) on a test.  Even if it
> would work, I don't want to have to put that annotation on every test
> because someone will forget and their tests will be silently skipped.
>
> *If* this class is in the same project as the rest of the integration
> tests, I can put this in the pom.xml:
>
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-failsafe-plugin</artifactId>
>                 <version>2.12.4</version>
>                 <executions>
>                     <execution>
>                         <id>integration-tests</id>
>                         <goals>
>                             <goal>integration-test</goal>
>                             <goal>verify</goal>
>                         </goals>
>                     </execution>
>                 </executions>
>                 <configuration>
>                     <includes>
>
> <include>**/DistributedIntegrationTestRunner.java</include>
>                     </includes>
>                     <skipITs>${skipITs}</skipITs>
>                 </configuration>
>             </plugin>
>
> When I do that, everything works exactly how I want.  But, if I move
> DistributedIntegrationTestRunner to a jar, that include no longer finds the
> DistributedIntegrationTestRunner.java (because it's not a java file
> anymore) and no tests get run.
>
>
>
> On Thu, Oct 17, 2013 at 4:32 PM, Russell Gold <russ@gold-family.us> wrote:
>
>> So, "this suite" is a set of tests? Or is it a test runner?
>>
>> If it's a test runner, and your tests are defined with a @RunWith
>> annotation that refers to it, just make it its own maven project and add it
>> as a dependency with "test" scope to the projects that contain the tests.
>>
>> On Oct 17, 2013, at 7:09 PM, Dan Kaplan <dank@mirthcorp.com> wrote:
>>
>> > The reason is that I want this suite to be reusable.  Its purpose is to
>> > allow different servers to run different integration tests based on the
>> > system properties given when it runs.  It was inspired by this article:
>> > http://blog.tradeshift.com/just-add-servers/
>> >
>> > All it does is look for all the integration testss and runs a portion of
>> > them.  This functionality needs to be reused in many projects that have
>> > long running integration tests.
>> >
>> >
>> > On Thu, Oct 17, 2013 at 3:51 PM, Russell Gold <russ@gold-family.us>
>> wrote:
>> >
>> >> OK, so you're doing something a bit unusual - is there some particular
>> >> reason that you are not compiling these tests in the project where you
>> want
>> >> to run them? That's the usual way, and everything is set up to work
>> with
>> >> that assumption.
>> >>
>> >> But if your tests are built separately by another maven project, all
>> you
>> >> need to do is make the jar that contains the test into a test
>> dependency of
>> >> the project where you want to run it.
>> >>
>> >>
>> >> On Oct 17, 2013, at 6:36 PM, Dan Kaplan <dank@mirthcorp.com> wrote:
>> >>
>> >>> Yeah this is a JUnit annotation.
>> >>> http://junit.sourceforge.net/javadoc/org/junit/runner/RunWith.html I
am
>> >>> passing in
>> >>>
>> http://junit.sourceforge.net/javadoc/org/junit/runners/AllTests.htmlinto
>> >>> that annotation.  org.junit.runners.AllTests is a test runner.  It
>> calls
>> >>> the suite() method on the pojo I've created.  I'm trying to figure out
>> >> how
>> >>> to say, "run this suite" in maven even though the class is in a jar.
>>  I
>> >>> only want to run this suite.  But "includes" only lets me specify file
>> >>> patterns instead of classpath patterns, as far as I can tell.
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> On Thu, Oct 17, 2013 at 3:20 PM, Russell Gold <russ@gold-family.us>
>> >> wrote:
>> >>>
>> >>>> Hi Dan,
>> >>>>
>> >>>> Is this the JUnit annotation, that you mean? And your tests use
it to
>> >>>> refer to a test runner?
>> >>>>
>> >>>> Your description is a bit confusing, since in JUnit, you use the
>> >> @RunWith
>> >>>> annotation on a test class to refer to another class which IS a
test
>> >>>> runner. You don't annotate a POJO with it, as far as I can tell.
>> >>>>
>> >>>> Now if you do mean a test runner that your test classes are referring
>> >> to,
>> >>>> you just need to make it  a maven artifact and add it to your test
>> >>>> dependencies.
>> >>>>
>> >>>> Regards,
>> >>>> Russ
>> >>>>
>> >>>> On Oct 17, 2013, at 4:49 PM, Dan Kaplan <dank@mirthcorp.com>
wrote:
>> >>>>
>> >>>>> Minor correction:  This isn't a test runner, but a pojo with
the
>> >> @RunWith
>> >>>>> annotation on it.
>> >>>>>
>> >>>>>
>> >>>>> On Thu, Oct 17, 2013 at 1:23 PM, Dan Kaplan <dank@mirthcorp.com>
>> >> wrote:
>> >>>>>
>> >>>>>> I've made my own test runner for integration tests that
I want to
>> >>>> execute,
>> >>>>>> but I've put it in a reusable jar.  I'm trying to tell failsafe
to
>> use
>> >>>> it
>> >>>>>> but I'm not sure how to because [the documentation for includes][1]
>> >>>> says:
>> >>>>>>
>> >>>>>>> A list of <include> elements specifying the tests
(by pattern)
>> that
>> >>>>>> should be included in testing. When not specified and when
the test
>> >>>>>> parameter is not specified, the default includes will be
>> >>>>>>
>> >>>>>>>  <includes>
>> >>>>>>   <include>**/IT*.java</include>
>> >>>>>>   <include>**/*IT.java</include>
>> >>>>>>   <include>**/*ITCase.java</include>
>> >>>>>>  </includes>
>> >>>>>>
>> >>>>>>> Each include item may also contain a comma-separated
sublist of
>> >> items,
>> >>>>>> which will be treated as multiple  <include> entries.
>> >>>>>>  This parameter is ignored if the TestNG suiteXmlFiles parameter
is
>> >>>>>> specified.
>> >>>>>>
>> >>>>>> But this test runner is in the classpath, not on the filesystem.
>>  How
>> >>>> can
>> >>>>>> I tell failsafe to use my class runner and only my class
runner?
>> >>>>>>
>> >>>>>> [1]:
>> >>>>>>
>> >>>>
>> >>
>> http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#includes
>> >>>>>>
>> >>>>>> --
>> >>>>>> Thanks,
>> >>>>>> Dan
>> >>>>>>
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>> --
>> >>>>> Thanks,
>> >>>>> Dan
>> >>>>>
>> >>>>> --
>> >>>>> CONFIDENTIALITY NOTICE: The information contained in this electronic
>> >>>>> transmission may be confidential. If you are not an intended
>> recipient,
>> >>>> be
>> >>>>> aware that any disclosure, copying, distribution or use of the
>> >>>> information
>> >>>>> contained in this transmission is prohibited and may be unlawful.
If
>> >> you
>> >>>>> have received this transmission in error, please notify us by
email
>> >> reply
>> >>>>> and then erase it from your computer system.
>> >>>>
>> >>>> -----------------
>> >>>> Author, Getting Started with Apache Maven <
>> >>>> http://www.packtpub.com/getting-started-with-apache-maven/video>
>> >>>>
>> >>>> Come read my webnovel, Take a Lemon <http://www.takealemon.com>,
>> >>>> and listen to the Misfile radio play <
>> >>>> http://www.fuzzyfacetheater.com/misfile/>!
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>
>> >>>
>> >>> --
>> >>> Thanks,
>> >>> Dan
>> >>>
>> >>> --
>> >>> CONFIDENTIALITY NOTICE: The information contained in this electronic
>> >>> transmission may be confidential. If you are not an intended
>> recipient,
>> >> be
>> >>> aware that any disclosure, copying, distribution or use of the
>> >> information
>> >>> contained in this transmission is prohibited and may be unlawful. If
>> you
>> >>> have received this transmission in error, please notify us by email
>> reply
>> >>> and then erase it from your computer system.
>> >>
>> >> -----------------
>> >> Author, Getting Started with Apache Maven <
>> >> http://www.packtpub.com/getting-started-with-apache-maven/video>
>> >>
>> >> Come read my webnovel, Take a Lemon <http://www.takealemon.com>,
>> >> and listen to the Misfile radio play <
>> >> http://www.fuzzyfacetheater.com/misfile/>!
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >
>> >
>> > --
>> > Thanks,
>> > Dan
>> >
>> > --
>> > CONFIDENTIALITY NOTICE: The information contained in this electronic
>> > transmission may be confidential. If you are not an intended recipient,
>> be
>> > aware that any disclosure, copying, distribution or use of the
>> information
>> > contained in this transmission is prohibited and may be unlawful. If you
>> > have received this transmission in error, please notify us by email
>> reply
>> > and then erase it from your computer system.
>>
>> -----------------
>> Author, Getting Started with Apache Maven <
>> http://www.packtpub.com/getting-started-with-apache-maven/video>
>>
>> Come read my webnovel, Take a Lemon <http://www.takealemon.com>,
>> and listen to the Misfile radio play <
>> http://www.fuzzyfacetheater.com/misfile/>!
>>
>>
>>
>>
>>
>>
>>
>>
>
>
> --
> Thanks,
> Dan
>



-- 
Thanks,
Dan

-- 
CONFIDENTIALITY NOTICE: The information contained in this electronic 
transmission may be confidential. If you are not an intended recipient, be 
aware that any disclosure, copying, distribution or use of the information 
contained in this transmission is prohibited and may be unlawful. If you 
have received this transmission in error, please notify us by email reply 
and then erase it from your computer system.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message