You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Daniel Kulp <da...@iona.com> on 2007/03/02 18:15:10 UTC

Move to JUnit 4?

With the move to Surefire 2.3, we can finally use JUnit 4 if we want to.   
I've done a small amount of investigation to see what would be needed.   
MOST of our unit tests will run unmodified with JUnit 4 and would not need 
to be updated.    The tests that don't run are the ones that require a 
pre-class setup (use a "suite" method).    Those would need to be updated.   
They are pretty simple to update.   The "suite" method is changed to be 
something like:

@BeforeClass
public static void startservers() {
....
}
@AfterClass
public static void stopservers() {
.....
}
and all the test methods need a @Test annotation.


The tests that would need modification include:
1) JMS tests (startup broker)
2) One of the WS Policy tests (just simple setup/teardown)
3) A BUNCH of the System tests.

A couple hours of work would do it.   However, what are peoples thoughts on 
moving to JUnit 4?


The main thing I like about it is to disable a test, you can add an @Ignore 
annotation.    This then shows up when you run "mvn test" as a skipped 
test.   It's much easier to find disabled tests so you know where they are 
to fix them later.

Thoughts?     
-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog

Re: Move to JUnit 4?

Posted by Peter Jones <pe...@iona.com>.
Hi Dan,

On Mon, Mar 05, 2007 at 10:58:14AM -0500, Daniel Kulp wrote:
> 
> 
> Anyone have any thoughts about this (one way or the other)?
> 
> Speak now.   I'll do this by Lazy Consensus
> (http://www.apache.org/foundation/glossary.html#LazyConsensus) later this 
> week if no-one objects.

I'm +1 for this.  As you mentioned, it would definitely be nice to be able
to see "skipped" tests.  For instance I know for sure there's a few handler
systests which have been disabled by appending an "s" to the method name...

Cheers,
Peter

> Dan
> 
> 
> On Friday 02 March 2007 12:15, Daniel Kulp wrote:
> > With the move to Surefire 2.3, we can finally use JUnit 4 if we want to.
> > I've done a small amount of investigation to see what would be needed.
> > MOST of our unit tests will run unmodified with JUnit 4 and would not
> > need to be updated.    The tests that don't run are the ones that
> > require a pre-class setup (use a "suite" method).    Those would need to
> > be updated. They are pretty simple to update.   The "suite" method is
> > changed to be something like:
> >
> > @BeforeClass
> > public static void startservers() {
> > ....
> > }
> > @AfterClass
> > public static void stopservers() {
> > .....
> > }
> > and all the test methods need a @Test annotation.
> >
> >
> > The tests that would need modification include:
> > 1) JMS tests (startup broker)
> > 2) One of the WS Policy tests (just simple setup/teardown)
> > 3) A BUNCH of the System tests.
> >
> > A couple hours of work would do it.   However, what are peoples thoughts
> > on moving to JUnit 4?
> >
> >
> > The main thing I like about it is to disable a test, you can add an
> > @Ignore annotation.    This then shows up when you run "mvn test" as a
> > skipped test.   It's much easier to find disabled tests so you know
> > where they are to fix them later.
> >
> > Thoughts?

-- 
Peter Jones
IONA Technologies Inc.
E-Mail: mailto:peter.jones@iona.com
Tel: (w) 709-738-3725 x22 | Fax: 709-738-3745
84-86 Elizabeth Ave. St. John's, NL A1A 1W7 Canada

Re: Move to JUnit 4?

Posted by Daniel Kulp <da...@iona.com>.

Anyone have any thoughts about this (one way or the other)?

Speak now.   I'll do this by Lazy Consensus
(http://www.apache.org/foundation/glossary.html#LazyConsensus) later this 
week if no-one objects.

Dan


On Friday 02 March 2007 12:15, Daniel Kulp wrote:
> With the move to Surefire 2.3, we can finally use JUnit 4 if we want to.
> I've done a small amount of investigation to see what would be needed.
> MOST of our unit tests will run unmodified with JUnit 4 and would not
> need to be updated.    The tests that don't run are the ones that
> require a pre-class setup (use a "suite" method).    Those would need to
> be updated. They are pretty simple to update.   The "suite" method is
> changed to be something like:
>
> @BeforeClass
> public static void startservers() {
> ....
> }
> @AfterClass
> public static void stopservers() {
> .....
> }
> and all the test methods need a @Test annotation.
>
>
> The tests that would need modification include:
> 1) JMS tests (startup broker)
> 2) One of the WS Policy tests (just simple setup/teardown)
> 3) A BUNCH of the System tests.
>
> A couple hours of work would do it.   However, what are peoples thoughts
> on moving to JUnit 4?
>
>
> The main thing I like about it is to disable a test, you can add an
> @Ignore annotation.    This then shows up when you run "mvn test" as a
> skipped test.   It's much easier to find disabled tests so you know
> where they are to fix them later.
>
> Thoughts?

-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog

Re: Move to JUnit 4?

Posted by Daniel Kulp <da...@iona.com>.
Since there are no objections, I'm going to go ahead and commit this. 

Things I've done:
1) Converted all of "common" to use junit 4
2) Converted all the subclasses of AbstractClientServerTest to use junit 4
3) Converted all the subclasses of CXFAbstractTest to use junit 4
4) Converted all the system tests to use junit 4
5) Converted all the jms tests to use junit 4
6) Converted some of the ws tests to junit 4.

In all cases, if I saw tests that were renamed (like xtestFoo()), I named 
it back and added a @Ignore annotation.   If I saw tests commented out, I 
tried to uncomment it.  If it compiled, I added a @Ignore annotation.   If 
it didn't compile, I left it commented out.   Anyway, while the tests run, 
you should see some "skipped" tests.   If they are in an area you are 
working on, please investigate why and see if they can be re-enabled.

Also if you are updating/adding tests someplace, please try and update them 
to junit 4 form.   It's mostly just change the superclass to 
org.junit.Assert, add @Before/@After annotations to setUp/tearDown, and 
@Test annotations to all the tests.

If you have some static setup that you want run before/after the entire set 
of tests, add @BeforeClass/@AfterClass annotations to static methods.  
(Example: create a single bus to use for all the tests instead of a bus 
per test.   Would make the tests run faster if there aren't side effects 
in the bus.)


Dan



On Friday 02 March 2007 12:15, Daniel Kulp wrote:
> With the move to Surefire 2.3, we can finally use JUnit 4 if we want to.
> I've done a small amount of investigation to see what would be needed.
> MOST of our unit tests will run unmodified with JUnit 4 and would not
> need to be updated.    The tests that don't run are the ones that
> require a pre-class setup (use a "suite" method).    Those would need to
> be updated. They are pretty simple to update.   The "suite" method is
> changed to be something like:
>
> @BeforeClass
> public static void startservers() {
> ....
> }
> @AfterClass
> public static void stopservers() {
> .....
> }
> and all the test methods need a @Test annotation.
>
>
> The tests that would need modification include:
> 1) JMS tests (startup broker)
> 2) One of the WS Policy tests (just simple setup/teardown)
> 3) A BUNCH of the System tests.
>
> A couple hours of work would do it.   However, what are peoples thoughts
> on moving to JUnit 4?
>
>
> The main thing I like about it is to disable a test, you can add an
> @Ignore annotation.    This then shows up when you run "mvn test" as a
> skipped test.   It's much easier to find disabled tests so you know
> where they are to fix them later.
>
> Thoughts?

-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog