Questions tagged [junit4]

Version 4 of the popular Junit Java Unit testing framework

Version 4 of the popular JUnit Java Unit testing framework.

New features are the introducing of annotations to use the framework.

Use this tag only for question related to features provided by version 4. Use for general questions.

3828 questions
1
vote
1 answer

How to call a set-up method before certain JUnit tests

I am creating unit tests with JUnit for methods that manipulate JSON objects. I want to create a method in my test file that sets up the object that will be used in some, but not all, of my test methods. How do I selectively run the set-up method…
cjmaria
  • 183
  • 3
  • 12
1
vote
1 answer

How to access application.property variable value into test class

I am using spring data jpa for creating microservices. I am trying to write test cases for controller. Now In controller url I am accessing InstituteIdentifier variable value from application.property file. In AccountController class I am getting…
HKAK
  • 79
  • 6
1
vote
2 answers

JUnit-Test started with Ant gives a "ClassNotFoundException"

This Ant-Target works: so "dist/FBChatSoft.jar" is the correct path to the jar. But the following target doesn't work. The Path to the *Test.java is also…
1
vote
0 answers

Elasticsearch Springboot Integration Test

I am trying to add an embedded elasticsearch to my spring boot integration test. The problem here is that initializing a node does not work together with spring boot as both should use different test runners. This is the error I'm…
varshavp27
  • 167
  • 1
  • 13
1
vote
1 answer

Why is comparison of double in Eclipse and maven different?

I have program where I am loading properties from file. When property is not present in config file in code I set the property to default value. In JUnit test I am testing that if property is not set that the value is the default value. My property…
user1097772
  • 3,191
  • 13
  • 51
  • 91
1
vote
1 answer

Hamcrest: how to use either/or combinable matchers with Collections

I am writing some JUnit/Aqruillian class test to test some persistence methods with Hibernate. So I have to get many lists of Hibernate entities from DB and to better write my tests I am using JUnit Hamcrest framework. In this moment, I would like…
SagittariusA
  • 4,795
  • 15
  • 57
  • 112
1
vote
1 answer

java.lang.ClassCastException: java.util.HashMap cannot be cast to com.spacestudy.model.Investigator

I am trying to write test case for Repository method. In that Test case I want to test Investigator name using assertEquals(). Return type of method is set for that I use for each loop to retrieve result from set and then checked expected and…
SpringUser
  • 931
  • 1
  • 18
  • 42
1
vote
1 answer

Test exception of a method which contains try catch in junit

I have code snippet below. What I want is if getNames() method catch an exception ( ex. InterruptedException ), want to check if Got InterruptedException !!! prints out or not. There are some examples of testing exception for a method which…
user2761895
  • 1,023
  • 3
  • 12
  • 31
1
vote
1 answer

Wanted but not invoked: but there were zero interactions with this mock

I am learning junit testing with spring boot I am trying To write test case for AccountController class. Account controller is depends on Account service. I used mockito for that. But I am getting error as zero interaction with…
SpringUser
  • 931
  • 1
  • 18
  • 42
1
vote
1 answer

DBUnit insists on inserting null for unspecified values, but I want the DB default value to be used

I'm having this problem with DBUnit causing a SQL insert error. Say I have this in my dbunit testdata.xml file: I have a table like this (postgres) myschema.mytable has an id, value1, value2,…
MTR
  • 1,361
  • 4
  • 13
  • 22
1
vote
2 answers

Visual Studio Code launch.json file for JUnit?

Can someone point me toward a sample launch.json file for JUnit 4 so I can run tests from Visual Studio Code? I am unable to find an example of this online and all attempts to create one have failed. I am able to run tests manually from the command…
Andr
  • 633
  • 3
  • 8
  • 15
1
vote
5 answers

Create a file which cannot be deleted by file.delete()

Note: I am aware there are several questions similar to this one, however, I cannot find any which explain how to resolve the situation I am trying to resolve. I will ask this question with a specific example, for which I need a solution. Consider…
Marcus MacWilliam
  • 542
  • 1
  • 3
  • 21
1
vote
0 answers

Can't create handler inside thread that has not called Looper.prepare() in Parameterized.class junit test

I want to create a test case and use the same test case several times but with different data, as shown below. @RunWith(Parameterized.class) public class ExampleInstrumentedTest extends TestCase { private MainActivity ma = new MainActivity(); …
1
vote
0 answers

Running main class in test directory

I have a very basic gradle project, and have a test file with main(). The file - "src/test/javaTestRunner.java" is as follows: import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.junit.runner.notification.Failure; public…
Ahmed A
  • 2,702
  • 5
  • 31
  • 50
1
vote
2 answers

Powermock withArguments call with variable input

I have test and class under test, which uses time in file name. Test code: SimpleDateFormat simpleDateFormatTimestamp = new SimpleDateFormat("yyMMddHHmmss"); String outputpath= inboundDir+inboundFilePrefix+simpleDateFormatTimestamp.format(new…
nBhati
  • 23
  • 1
  • 8
1 2 3
99
100