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.

4127 questions
1
vote
2 answers

How to cover the While block with Iterator and catch in a method with mockito and Junit4?

I must covered whit Junit4 and Mockito/PowerMockito the While Block and the catch block. The Exception StateException is launched by the getHrest method public class Fstate{ …. private Date selectedDate; private Date dateYes; private…
Dep
  • 11
  • 4
1
vote
2 answers

Is there ErrorCollector rule analogue for JUnit5

There was the ErrorCollector Rule in JUnit4 and now we have to switch to extensions during migration to JUnit5. Usage of the ErrorCollector was described here https://junit.org/junit4/javadoc/4.12/org/junit/rules/ErrorCollector.html Is there a…
1
vote
1 answer

Mock whenever new instance created without PowerMockito JUnit5

JUnit5 does not support PowerMockRunner hence the following code will not work whenever you migrate from JUnit4 to JUnit5. Eg. Code you trying to inject mock import javax.naming.InvalidNameException; public class Main { public static void…
Eranda
  • 1,439
  • 1
  • 17
  • 30
1
vote
1 answer

Selenium Test (junit ) get stuck once the test spawns new window

Issue is once the new window is spawn test hangs after the line waitForPageToLoad(3000) and finally times out. Once the test hangs if i manually fire some event in parent window test starts executing normally. So as a solution I tried adding code…
Vral
  • 441
  • 1
  • 4
  • 7
1
vote
2 answers

findById returning empty in Junit Test case

I am testing update Employee method using junit. Here is junit code looks like @RunWith(SpringJUnit4ClassRunner.class) public class EmployeeServiceTest { @InjectMocks EmployeeService service; @Mock EmployeeRepository…
Unknown Guy
  • 107
  • 3
  • 3
  • 11
1
vote
0 answers

How to mock user defined Annotation with Mockito

I'm writing test cases for my controller layer. One Of my controller method looks like below. import org.slf4j.Logger; import org.slf4j.LoggerFactory; @RestController @RequestMapping("/v1") public class MyController { private static Logger…
Mahesh Yadav
  • 240
  • 2
  • 3
  • 13
1
vote
1 answer

Unable to print all test results in a testcase using JUnit

I have written a TestCase using a Runner class to print the results. But when I try to print the results, I am getting only the first result and not all failures/results of the TestCase. My TestCase class is as below: public class Fixtures_JavaTest…
user2755407
  • 348
  • 1
  • 3
  • 15
1
vote
1 answer

Parameterized junit test of custom validation in springboot

I have this validator in springboot which gives error when an integer is not between 1 and 3 and i am using addConstraintViolation to print a message from properties file public class SizeValidator implements ConstraintValidator
Catalina
  • 663
  • 5
  • 20
1
vote
0 answers

How to use mockito to mock java reflect Method and its methods

I'm using Mockito (3.6.x) for my unit tests in Spring Boot (2.4.x) with JUnit 4. I need to test the next code block: MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); Method method =…
1
vote
0 answers

Properties in RestController is not accessible and Null in Junit

When i run my junit for Rest Controller class, properties in Rest controller is throwing Nullpointer exception. Below is my sample code. when i run the testFileStatus() method of TestingControllerTest calass, i am getting Nullpointer exception.…
1
vote
2 answers

Providing order to Test class execution Java

I have three test classes to test my controller, service and Kafka Messaging. When I run the Kafka messaging standalone, it works. But when I run all my test files together, the Kafka test class passes as long as it is the first one that gets…
Abhinav Mehrotra
  • 543
  • 2
  • 8
  • 17
1
vote
1 answer

JUnit: obj cannot be resolved

I made a small Java program using JUnit 4. I wrote two methods, one with a @Before annotation and one with @Test. I created an object of a class obj but it says obj can't be resolved. @Before public void objectCreation() { Main obj = new…
1
vote
0 answers

java.lang.IllegalStateException for robolectric

I am writing a local unit tests for shard pref, I have three test cases, the one-pass than I got java.lang.IllegalStateException: Already initialized at com.yariksoffice.lingver.Lingver$Companion.init(Lingver.kt:192) at…
العبد
  • 359
  • 5
  • 15
1
vote
3 answers

How to write Junit Test Cases in springBoot?

Thid is my mapping from my controller class , now I want to write unit test case for the same @GetMapping(value = "/tokenSearch/{id}/{name}/{values}/{data_name}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity
user15316614
1
vote
1 answer

Java Selenium Potential Chrome Cookies, Driver, ExpectedConditions API Issue?

INTRO: I am a student using Java Selenium for GUI testing. I cannot get test cases to run on my desktop but other members of my team are able to. WHAT TECH/SOFTWARE IS BEING USED We are using JDK 14, IntelliJ Community Edition, BitBucket for our…
1 2 3
99
100