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
0 answers

How to simulate caught and logged exceptions inside a method and create JUnit tests

I have to write JUnit test cases for existing code where I do not have the liberty / opportunity to re-write the actual code. In many of these classes, the methods catch an exception internally and just log it. And the exceptions are not based on…
adbdkb
  • 1,331
  • 4
  • 26
  • 45
1
vote
2 answers

Issue trying to test a Controller that have a Services that have a Repository (Spring Boot)

I'm trying to build a test to the ClienteController.java that uses the ClienteService.java that use ClienteRepository.java to the Cliente.class I'm running the tests using the mvn test command. So I am trying to use the WebMvcTest to isolate the…
1
vote
1 answer

How to add test coverage to Camunda Spring Boot application?

I want to add test coverage to my JUnit tests for my BPMN files. I read Camunda BPM Process Test Coverage and tried the Spring example with the Camunda Spring Boot Starter test configuration, but I get an…
dur
  • 13,039
  • 20
  • 66
  • 96
1
vote
2 answers

Spring Boot, Mockito, injecting mock into scope session bean

I'm having a problem injecting mock into one class I need for testing. I'm trying to mock a Dao class and had no problem doing so using ReflectionTestUtils in various services I'm using, however this one just does not want to work, it keeps calling…
AragornSG
  • 552
  • 5
  • 17
1
vote
1 answer

Can't test spring injection with JUnit

I can't manage to test the injection. I don't know how the testing works between JUnit and Spring, after reading contents I learnt that we need to have the same package name but in a different directory. So that's what I did but it is nto…
Akd
  • 53
  • 4
1
vote
1 answer

How to Mock or Stub a protected method from abstract parent while testing a public method in child with both in different packages

I have legacy code that I can't change but I need to cover with a JUnit test. I've been trying out various Mockito and PowerMockito usages to no avail. Abstract Parent package com.parent; public abstract class Parent { public Parent() { …
Daniel M
  • 13
  • 2
1
vote
1 answer

Mock class object as parameter of function

I am using junit and mokito to write unit test of my java program. public MyClass { private ClassA a; public void process(ClassB b) { if(b.method()) a = ClassA.builder().build(); } } Now I have write a MockClassA and…
Feihua Fang
  • 561
  • 1
  • 5
  • 14
1
vote
1 answer

how to convert return type of method within when().thenReturn method of Mockito

Below is my code snippet. This is giving me compilation error, as env.getProperty will return String. How do I get integer value. Interger.ParseInt is not working. when(this.env.getProperty("NeededIntegerValue")).thenReturn(15); Below is my test…
1
vote
1 answer

Jenkins build fails because it is looking for log path defined in logback.xml when executing junit test

I am getting the following error on Jenkins when I try to do a gradle build of my code along with Junit tests: Caused by: java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected: ERROR in…
Ajay C.V.
  • 13
  • 3
1
vote
2 answers

"DataPoint field samples must be public" error when using JUnit 4 Theories in Kotlin

Overview Applying @DataPoint or @DataPoints to a property in a Kotlin class results in "DataPoint field samples must be public" error. Description Theories in JUnit4 use @DataPoint and @DataPoints annotations to mark sample data which is collected…
outis
  • 68,704
  • 19
  • 132
  • 197
1
vote
1 answer

Mockito is unable to create instance using @InjectMocks because of Static class in constructor

I have to unit test in some code(Not written by me), but I am stuck at one place. I am using Powermock and mockito. So the issue is @InjectMocks call default constructor before even testing a method, inside the default constructor, they have used a…
Avinash Kharche
  • 352
  • 3
  • 18
1
vote
2 answers

Mockito verify not working correctly

I am quite new to Mockito, though I have been running tests successfully before and today it just look so strange why mockito verify() method keeps telling me that a View method is required but not called even though I am sure Presenter method is…
Tosin John
  • 464
  • 4
  • 14
1
vote
3 answers

How to skip @PostConstruct when unit testing

I have a scheduled task that aggregates data every night. The task runs whenever I start up the application and I would like to stop it from running when I run jUnit tests on the applicaton. @Scheduled(cron = "0 0 0 1 * ?") public void…
gnommando
  • 13
  • 1
  • 4
1
vote
0 answers

Why does path resolution change in a multi-module project when trying to load resources in a test?

I have a file in my src/main/resources folder in a multi-module Gradle project: modulename/src/main/resources/file If I try to load it from my program it works just fine: new File("modulename/src/main/resources/file").exists() // true but when I…
Hexworks
  • 491
  • 4
  • 16
1
vote
3 answers

Ant build target is failing after first junit task

I have an Ant build target that performs some testing using jUnit4
Olegas
  • 9,749
  • 7
  • 46
  • 70
1 2 3
99
100