When you say "just use junit", I have this test that I thought behaves the
same as invoking my Mojo ...
public class TestSeleniumTestMojo extends AbstractMojoTestCase {
...
public void testNoHosts() throws Exception {
try {
final File pom =
getTestFile("src/test/resources/TestSeleniumNoHosts-pom.xml");
assertNotNull(pom);
assertTrue(pom.exists());
final SeleniumTestMojo myMojo = (SeleniumTestMojo) lookupMojo(GOAL,
pom);
// Should have thrown an exception by now.
fail();
} catch (final Exception e) {
e.printStackTrace();
}
}
but no "MojoFailureException is being thrown by the "lookupMojo" method even
though I can see in my logs the place where a MojoExecutionException is
being thrown by my custom Mojo. What gives with the JUnit code above? -
Dave
Robert Scholte wrote:
>
>
> Your example tries to check if hosts is set.You can do this by adding
> @required doclet-tag to the field. Now Maven (actually Plexus) will check
> it for you. If you simple, plain old test, just use junit.But if you
> depend on injection you should try the maven-invoker-plugin. It's nothing
> more than making mini-projects, trying to run it with Maven and optionally
> verify the outcome. -Robert
> > Date: Thu, 11 Aug 2011 11:43:00 -0700
>> From: [email protected]
>> To: [email protected]
>> Subject: Re: [mojo-user] Integration testing for my custom Mojo
>>
>>
>> In my custom Mojo project, I'm trying to write tests in my src/test/java
>> directory that will validate I'm throwing the correct errors when I have
>> a
>> mis-configuration. Although I'm fairly new to Maven, don't all tests in
>> src/test/java have to be in Java/JUnit? - Dave
>>
>>
>>
>> Anders Hammar wrote:
>> >
>> > No, but I could easily be used to verify that the pom configuration is
>> > correct. Or do you *have* to use JUnit?
>> >
>> > /Anders
>> >
>> > On Thu, Aug 11, 2011 at 20:17, laredotornado
>> > <[email protected]>wrote:
>> >
>> >>
>> >> Is the invoker plugin intended to be used in a JUnit context? I
>> wanted
>> >> to
>> >> write my integration tests using JUnit 4 but can't find an example
>> that
>> >> has
>> >> Java code to do this. Thanks, - Dave
>> >>
>> >>
>> >>
>> >> Anders Hammar wrote:
>> >> >
>> >> > I would use the invoker plugin. If you look at nearly any maven
>> plugin
>> >> > here
>> >> > at Mojo (the source code), you'll see examples of that type of
>> >> integration
>> >> > testing.
>> >> >
>> >> > /Anders
>> >> >
>> >> > On Wed, Aug 10, 2011 at 16:09, laredotornado
>> >> > <[email protected]>wrote:
>> >> >
>> >> >>
>> >> >> Hi,
>> >> >>
>> >> >> I'm developing my own custom Mojo. I want to test the case where
>> >> someone
>> >> >> hasn't entered the correct configuration, so my code has …
>> >> >>
>> >> >>
>> >> >> public class SeleniumTestMojo extends AbstractMojo {
>> >> >>
>> >> >> ...
>> >> >> public void execute() throws MojoExecutionException {
>> >> >> try {
>> >> >> …
>> >> >> // Verify hosts are non-empty.
>> >> >> if (hosts != null && hosts.isEmpty()) {
>> >> >> throw new MojoExecutionException("Plugin execution
>> requires
>> >> >> one
>> >> >> or more hosts.");
>> >> >> }
>> >> >>
>> >> >>
>> >> >> I have an XML file that represents the misconfigured plugin, but I
>> >> have
>> >> >> no
>> >> >> idea how to write an integration test to check for this kind of
>> >> >> exception.
>> >> >> Any advice or examples about writing integration tests is greatly
>> >> >> appreciated, - Dave
>> >> >>
>> >> >>
>> >> >> --
>> >> >> View this message in context:
>> >> >>
>> >>
>> http://old.nabble.com/Integration-testing-for-my-custom-Mojo-tp32234324p32234324.html
>> >> >> Sent from the mojo - user mailing list archive at Nabble.com.
>> >> >>
>> >> >>
>> >> >>
>> ---------------------------------------------------------------------
>> >> >> To unsubscribe from this list, please visit:
>> >> >>
>> >> >> http://xircles.codehaus.org/manage_email
>> >> >>
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://old.nabble.com/Integration-testing-for-my-custom-Mojo-tp32234324p32244345.html
>> >> Sent from the mojo - user mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe from this list, please visit:
>> >>
>> >> http://xircles.codehaus.org/manage_email
>> >>
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Integration-testing-for-my-custom-Mojo-tp32234324p32244564.html
>> Sent from the mojo - user mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>
>
--
View this message in context:
http://old.nabble.com/Integration-testing-for-my-custom-Mojo-tp32234324p32244933.html
Sent from the mojo - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email