junit

JUnit java.lang.OutOfMemoryError when running all tests in a package

When loading all unit tests in a package, the make task throws a java.lang.OutOfMemoryError: Java heap space error. If I run all the tests in each subpackage, though, all tests load and complete just fine. It is only when I try to run all tests in the parent package that the OOM error occurs. I don't think this problem should be solved...

Running JUnit test in NetBeans gives NoSuchMethodError error on a method whose return type was changed

I have a project in NetBeans with JUnit tests. I made a change to a method return type in a dependent project, and the app runs fine. But when I run the JUnit test from inside NetBeans I get a NoSuchMethodError. I made sure to clean and build. ...

Run JUnit automatically when building Eclipse project

I want to run my unit tests automatically when I save my Eclipse project. The project is built automatically whenever I save a file, so I think this should be possible in some way. How do I do it? Is the only option really to get an ant script and change the project build to use the ant script with targets build and compile? Update I w...

Include NUnit in my Open-Source Project Download?

I'm considering two possibilities: include NUnit with the source code of an open-source project - to make it very easy for the potential contributors to run automated tests right away. I feel it is important to promote the "tests-first" culture in this project (or at least make it clear to everyone that tests matter). distribute the ...

Running ant build gives "package org.junit does not exist"

When I use a Java IDE to build projects (e.g. NetBeans) that have JUnit tests, they compile fine, but when I try to use ant outside of the IDE to run the build script, I get the error "package org.junit does not exist". ...

Ant+Junit works on first run and never again.

Hey guys I've been trying all day to get an ant file to automatically build my project. The file (appended below) was on a web page I found and is pretty thorough. My problem is that it works as long as I don't run the "clean" target. Once the I run the "clean" target the "test" target ceases to work. I get NoClassFound errors on all te...

How to instantiate a shared resource in JUnit

I noticed that jUnit runs the constructor of my test class for each method being tested. Here's an example: public class TestTest { protected BigUglyResource bur; public TestTest(){ bur=new BigUglyResource(); System.out.println("TestTest()"); } @Test public void test1(){ System.out.printf("test1()\n"...

Maven Surefire reports show multiple class entries rather than a suite.

Hello, I've been asked to configure Maven's surefire report generator to include one entry for the test suite which in turn tests classes A,B and C but instead of seeing this: A B C MySuite I see this A B C A B C So there's two problems really: 1) How do I stop the tests running twice. 2) How do I get the report to show me one entry pe...

Running Junit & PowerMock with Mockito through PowerMockRunner from maven

Hi, I am not being able to run Powermock through maven. I'm the PowerMock Mockito and PowerMockRunner for driving a jUnit test. Here's the test: @RunWith(PowerMockRunner.class) @PrepareForTest( { UserLocalServiceUtil.class, ExpandoBridge.class }) public class AlertNotificationsTest { //... I haven't configured anyting special for ru...

JUnit: Enable assertions in class under test

I've been bit a few times by Java assert statements that didn't fail in the JUnit test suite because assertions weren't enabled in JUnit's JVM instance. To be clear, these are "black box" assertions inside implementations (checking invariants, etc) not the assertions defined by the JUnit tests themselves. Of course, I'd like to catch any...

Should JUnit tests be javadocced?

I have a number of JUnit test cases that are currently not documented with Javadoc comments. The rest of my code is documented, but I'm wondering if it's even worth the effort to document these tests. ...

Junit import using * wildcard

I've noticed that when importing JUnit, the * wildcard doesn't always work. e.g. for the annotation @Test you must import org.junit.Test since org.junit.* doesn't recognize the annotation. Is there a reason for this, is it something that needs setting? or just a quirk in the way somethings like JUnit are. FYI, I am using: Junit 4.6, In...

AtUnit vs 'Junit,JMock and GUICE' by hand - ?

How does AtUnit fare with respect to unit testing using DI and guice ?. Please share your experiences. ...

Java JUnit: The method X is ambiguous for type Y

I had some tests working fine. Then, I moved it to a different package, and am now getting errors. Here is the code: import static org.junit.Assert.*; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.jgrapht.Graphs; import org.jgrapht.WeightedGraph; import org.jgrapht.graph.DefaultWeightedEdge; import or...

Hamcrest's lessThan doesn't compile

Trying to compile this code import static org.hamcrest.Matchers.is; import static org.hamcrest.number.OrderingComparison.lessThan; ... Assert.assertThat(0, is(lessThan(1))); issues this compilation error: assertThat(Object, org.hamcrest.Matcher<java.lang.Object>) cannot be applied to (int, org.hamcrest.Matcher<capture<? su...

Data-driven tests with jUnit

What do you use for writing data-driven tests in jUnit? (My definition of) a data-driven test is a test that reads data from some external source (file, database, ...), executes one test per line/file/whatever, and displays the results in a test runner as if you had separate tests - the result of each run is displayed separately, not in...

junit - share a fixture between testcase

i wonder whether it is possible to have a fixture that can be shared between testcases for instance a hibernate session. Thank you! ...

How to do a junit assert on a message in a logger

I have some code-under-test that calls on a java logger to report its status. In the junit test code, I would like to verify that the correct log entry was made in this logger. Something along the following lines: methodUnderTest(bool x){ if(x) logger.info("x happened") } @Test tester(){ // perhaps setup a logger first...

Spring Web Service Unit Tests: java.lang.IllegalStateExcepton: Failed to load Application Context

I am getting the error "java.lang.IllegalStateExcepton: Failed to load Application Context" when I am trying to run my unit test from within Eclipse. The Unit Test itself seems very simple: package com.mycompany.interactive.cs.isales.ispr.ws.productupgrade; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWit...

JUnit: pause for user input

I'm learning JUnit. Since my app includes graphical output, I want the ability to eyeball the output and manually pass or fail the test based on what I see. It should wait for me for a while, then fail if it times out. Is there a way to do this within JUnit (or its extensions), or should I just throw up a dialog box and assertTrue on th...