Questions tagged [junit]

Popular unit testing framework for Java and Scala. The latest version, JUnit 5, supports rich annotation-based and parameterized tests. Consider using in conjunction with the Java or Scala tag to indicate your use case.

JUnit is a popular unit testing framework for JVM languages (Java, Scala, Groovy, Kotlin, and others). The current version, JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage. Consider using in conjunction with the appropriate language tag (, , , and others) tag to indicate your use case. It is one of the most popular Java frameworks and is used in circa 30% of all projects.

The latest iteration, JUnit 5 (use tag ) adds Java 8 idioms, parameterized tests and comprehensive support for custom extensions.

There are JUnit implementations for other programming languages, which are called xUnit.

Kent Beck, Erich Gamma and David Saff created the unit testing framework influencing Java development heavily.

Grab JUnit's source code at GitHub or even fork it.

Related Links:

27795 questions
11
votes
2 answers

Running JUnit test suite using Maven

I have written a JUnit test suite for running multiple test cases. Now I want to run my test suite class (AllTest.java) at once so that all tests are triggered, carried and managed by one class. I know maven-failsafe-plugin is available, but is…
Chetan
  • 1,507
  • 7
  • 30
  • 43
11
votes
2 answers

Trying to run ANT JUnit target in debug mode in Eclipse

Here is my ANT JUnit target
MayoMan
  • 4,757
  • 10
  • 53
  • 85
11
votes
4 answers

How to test a timer?

I would like to write a test for a method, that calls observers in a specific intervall, so that they will execute a method. The timer-object runs in its own thread. Method of timer to be tested private long waitTime; public Metronome(int bpm) { …
ccaspers
  • 131
  • 1
  • 7
11
votes
6 answers

Internal Error (javaClasses.cpp:129)

I'm trying run a test with JUnit 4 and Robolectric on Eclipse but all time I receive this error: Invalid layout of java.lang.String at value # # A fatal error has been detected by the Java Runtime Environment: # # Internal Error…
Fran b
  • 3,016
  • 6
  • 38
  • 65
11
votes
4 answers

How to test content providers on Android

I am trying to test my DB using ProviderTestCase2. I can see the test DB being created. As such I suppose, the tested content provider should use the test DB. But as soon as I try any calls against the MockContentResolver (or the one created with…
charroch
  • 2,170
  • 2
  • 15
  • 14
11
votes
3 answers

How to test anonymous methods with JUnit or Mockito?

I have simple class but with anonymous block of code. I need to cover this class with tests. public class CleanerTask { private final Logger log = LoggerFactory.getLogger(getClass()); DataWarehouseMessageDao dwMessageDao; int…
Dmitrii Borovoi
  • 2,814
  • 9
  • 32
  • 50
11
votes
2 answers

Using JUnit Categories with Maven Failsafe plugin

I'm using JUnit Categories to separate integration tests from unit tests. The Surefire plugin configuration works - it skips the tests annotated with my marker interface IntegrationTest. However, the Failsafe plugin doesn't pick the integration…
brabec
  • 4,632
  • 8
  • 37
  • 63
11
votes
3 answers

Powermock, Mockito nullpointerexception when calling super() JDialog

I am getting a NullPointerException when I try to unit test some methods in a JDialog object. I have to initialize a mock version of the parent of the dialog as well as another class that will be used (in addition to calling a static method. The…
sldahlin
  • 685
  • 1
  • 8
  • 19
11
votes
2 answers

Intellij Idea "Move refactoring" with Junit tests

Seems when I make "move" refactoring all my junit tests lays on its old place. Often I tests "package" visible classes, so they becomes invisible, if SUT moves to another package. Do you move tests by hand?
dmitrynikolaev
  • 8,994
  • 4
  • 30
  • 45
11
votes
5 answers

How to obtain test case name in JUnit 4 at runtime?

I want to do some logging while executing my JUnit test. In JUnit 3.x it was always easy to obtain the name of the currently running test case, no matter how the test case was instantiated: public void testFoo() throws Exception() { String…
mkoeller
  • 4,469
  • 23
  • 30
11
votes
7 answers

Error! The first argument to the non-static Java function 'replace' is not a valid object reference

I am trying to get ANT to create an HTML report of a JUNIT test in Eclipse but after I created the ANT build I get the following errors when I run it: [junitreport] Processing C:\Documents and…
user1397000
  • 111
  • 1
  • 1
  • 4
11
votes
1 answer

How to ignore unexpected method calls in JUnit/easymock?

I'm just wondering if it is possible using Junit and easymock to ignore unexpected method calls? I.e. instead of the test failing I want to be able to say - "at this point - ignore any unexpected method calls and just continue with the test as…
Rory
  • 1,805
  • 7
  • 31
  • 45
10
votes
4 answers

Syntax error: insert "enum Identifier", insert "EnumBody", inset "}"

I coded an enum type which brings up the following Syntax errors when I run my created JUnit test for it: java.lang.Error: Unresolved compilation problems: Syntax error, insert "enum Identifier" to complete EnumHeaderName Syntax error,…
tkrishnan
  • 327
  • 3
  • 4
  • 11
10
votes
2 answers

Loading Properties File In JUnit @BeforeClass

I'm trying to load sample.properties from my classpath during my JUnit test execution and it can't find the file in the class path. If I write a Java Main class I'm able to load the file just fine. I'm using the below ant task to execute my JUnit.…
c12
  • 9,557
  • 48
  • 157
  • 253
10
votes
2 answers

Testing for custom plugin portlet: BeanLocatorException and Transaction roll-back for services testing

My Problems: I can test successfully for CRUD services operation. I was doing an insert on @Before [setUp()] and delete of same data on @After [tearDown()] but going forward I would need to support Transactions rather than writing code for insert…
Prakash K
  • 11,669
  • 6
  • 51
  • 109
1 2 3
99
100