*
The moose likes Ant, Maven and Other Build Tools and the fly likes Including maven test classes in to my war? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Including maven test classes in to my war?" Watch "Including maven test classes in to my war?" New topic
Author

Including maven test classes in to my war?

Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

Hi

I am attempting a jee6 ear project into a war. I need a way to include some test classes located in src/main/test into my final war. I am using war plugin during my buld. I am new to maven and although i know I can do this through ant, I am looking for simple way to do what will become a regular feature of my pom building.


SCJP 6.0, SCJD (400/400), SCBCD for JEE 5, SCWCD 1.4 I do videos for development at
http://www.youtube.com/user/thejartender?feature=mhee
I am probably the only developer ever to have had an orange sized brain tumor in my brain while learning development!!
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Why do you want the test classes in the final deliverable?

[My Blog] [JavaRanch Journal]
Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

Jaikiran Pai wrote:Why do you want the test classes in the final deliverable?



Wow hi! can almost call you neighbour from the jaboss forums over last few days:P

because these are cactus tests and new to me and it would seem that running them through the cactus servlet proxy is much easier. Yes i know there are various plugins that all seem outdated to allow maven to test during the build process. I however am looking to get to learn cactus as a framwework without maven. Note that I am keeping my test classes in the /main test directory but they are not included in my generated war.

I i were to ever meet you I would have to buy you more than just a round.
Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

Nothing in the maven war plugin so solution is wither put the test class in the same directory as the EJB being tested(very bad) or in a hihger level package like the controller package as he cactus.ServletTestCase is after all meant to mimic a servlet using your EJB. maven war artifact seems to only compile what is in project/main/src/java
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Yucca Nel wrote:


Wow hi! can almost call you neighbour from the jaboss forums over last few days:P


Hi!

Yucca Nel wrote:
Note that I am keeping my test classes in the /main test directory but they are not included in my generated war.



Those wont be included in the final deliverable. Maven's jar plugin has a test-jar goal which might be useful here. The details of that goal are here. I haven't played with the war plugin much, so not really sure how this can be integrated with the war plugin. Maybe you could create a test-jar and place that jar in the war/WEB-INF/lib folder.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Maven's normal test process doesn't include test classes in the deployable. Mostly because it's geared towards externally-applied unit testing.

A good way to include testing classes in a WAR is to use the Maven profile facility and define these classes as part of a testing profile. When testing, build with this profile. When doing a production build, don't activate the test profile and those classes won't be included.

It's been a while since I've looked at Cactus, but I'm not sure that it requires server-side code to do its thing. And if that's the case, Cactus shouldn't require any additions to the WAR in any case.

I prefer injectable testing myself just because I don't like having 2 different versions of an application. Things that work on the test version might not work (or worse, might work differently) on the production version. If there was a way to make positively sure that the differences were only in the testing itself, that would be OK, but such things have a bad habit of getting into the mainline logic.


Customer surveys are for companies who didn't pay proper attention to begin with.
Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

Tim Holloway wrote:Maven's normal test process doesn't include test classes in the deployable. Mostly because it's geared towards externally-applied unit testing.

A good way to include testing classes in a WAR is to use the Maven profile facility and define these classes as part of a testing profile. When testing, build with this profile. When doing a production build, don't activate the test profile and those classes won't be included.

It's been a while since I've looked at Cactus, but I'm not sure that it requires server-side code to do its thing. And if that's the case, Cactus shouldn't require any additions to the WAR in any case.

I prefer injectable testing myself just because I don't like having 2 different versions of an application. Things that work on the test version might not work (or worse, might work differently) on the production version. If there was a way to make positively sure that the differences were only in the testing itself, that would be OK, but such things have a bad habit of getting into the mainline logic.

Thank you, the profile facility looks like what I was in need of but will have to see next week as ocassionally we developers have weekends where we don't do much :P I think I need to go have a beer for Jai who I owe so much for much help this week.

Just as a note... (and I am sure you know) cactus provides the ablilty to configure a test servlet that will be run and take in a param of a class that is ultimatley your test class but this needs to be in the classpath or a CNFE is thrown. this seemed to be the less awkward way to run cactus tests and I therefore chose this a my default to run the tests. I can't for the life of me ge the maven ejbunit repository configured and the instructions should be changed on the EjB3 unit page. The way they are currently presented lead to configuration in which you may (as I ahave) prevent maven from accesing any repo including the default maven repo.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Including maven test classes in to my war?