Category Archives: JUnit

How to run a JUnit test multiple times

I had a Spring-enabled JUnit test that I needed to run multiple times. I thought there used to be a JUnit annotation, but I couldn’t find it. I found and used the Spring @Repeat annotation. I used to set breakpoints … Continue reading

Posted in JUnit, Spring, Test Driven Development, Unit Tests | Tagged , , , , , | Leave a comment

Cucumber Spring Integration

I have a normal Spring-enabled project arranged as a Maven project. There were already JUnit tests in the project, along with the requisite Spring configuration. I needed to add Cucumber tests to the project. I started by adding a cucumber … Continue reading

Posted in Cucumber, Integration Tests, Java, JUnit, Spring, TDD, Test Driven Development, Unit Tests | Tagged , , , , , , , , , | Leave a comment

Hamcrest matcher – not

Have you ever had the case where you had to test for the negative of something? I was helping a teammate who wanted to test that a collection was not empty. It was pretty hard to track down how to … Continue reading

Posted in hamcrest, Java, JUnit | Leave a comment

Expected exceptions in Junit

I had seen annotating a test class with @Test(expected = Exception.class) to test for exceptions before. In this case, we needed to test for Exception and the message was made the difference. This can be accomplished by @Rule

Posted in Integration Tests, Java, JUnit, Test Driven Development | Tagged , , , , , , , , , , | Leave a comment

AmazonWS and Spring

We had an existing web application that needed to handle images being stored in AmazonWS. Here is what I needed to do to add the new functionality. Add the AmazonWS Maven dependency Create the files that contain the AmazonWS credentials. … Continue reading

Posted in Java, JUnit, Maven, Spring | Leave a comment

Running out of heap space when running JUnit tests

The project finally got so large that the JUnit tests would run out of heap space during the tests. I added space to the IDEA maven runner, but that didn’t work. You have to add it to the maven-surefire plugin.

Posted in Java, JUnit, Maven | Leave a comment

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence

This is what you get when you try to test code that relies on Java EE APIs. You can compile the code because the javaee;javaee-api;5 dependency has stubs for the methods. Unfortunately, it does not contain implementations for the methods … Continue reading

Posted in Java, JUnit, Maven | Leave a comment