Showing posts with label JUnit4. Show all posts
Showing posts with label JUnit4. Show all posts

Friday, April 10, 2009

XmlUnit

XmlUnit is an insanely great tool. It has saved me a ton of time in the past few weeks.

I log the differences from my unit test like this :

        XMLUnit.setIgnoreWhitespace(true);
Diff xmlDiff = new Diff(expectedXml, result);

DetailedDiff myDiff = new DetailedDiff(xmlDiff);
List<Difference> allDifferences = myDiff.getAllDifferences();
for(Difference d : allDifferences){
log.debug("difference : " + d);
}


The "result" string comes from a Groovy class using XmlSlurper. Also I usually generate "expectedXml" from a Groovy class.

Wednesday, December 3, 2008

Unsigned JUnit 4 in JBoss Developer Studio

Running a JUnit4 test I got the following error :

junit.framework.JUnit4TestCaseFacade"'s signer information does not match signer information of other classes in the same package
Apparently other people have had the same problem with Europa.

The solution was easy.  I downloaded JUnit4 jars and created a new User Library with them.  I then added my new user library to the project and the run configuration.

To add the new library to the project :
  • I downloaded Junit4 and its' sources.
  • I put both jars in "/Users/[USER_NAME]/Java."
  • I control-clicked on the prject name and chose "Build Path -> Configure Build Path."
  • Under "Libraries" I removed the JUnit 4 library.
  • I clicked "Add Library -> User Library -> Next -> User Libraries -> New" and created a Library called "JUnit4 Local."
  • I added the jars I downloaded.

To add the new library to the run configuration :
  • Run Button -> Run Configurations
  • The most recently run test is highlighted.  Choose the one that needs to be changed.
  • Click the "Classpath" tab.
  • Expand "User Entries"
  • Remove the existing JUnit4 library.
  • Add the user library.