Questions tagged [junit5]
Version 5 of the popular JUnit testing framework for the JVM. JUnit is a framework for writing repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks.
3,602
questions
0
votes
0
answers
5
views
Field with @Mock annotation initialize vs. @BeforeAll
I have the following static mocking settings:
@ExtendWith(MockitoExtension.class)
TestClass{
@Mock
private static ClassB classBInstance;
@BeforeAll
static void setup(){
MockedStatic&...
0
votes
0
answers
36
views
How to mock calls to inherited methods
I have a method that I want to test. I don't get the mocking to work.
The method looks like this:
public TypeA collectData(Connection dbCon, String id){
TypeA a = new TypeA();
a.setTime(...
1
vote
0
answers
22
views
Error running tests in gradle using cucumber tags
Currently when I run a test using cucumber and junit tags I get an error when I run the command:
gradle test -DCucumber.options="--tags @LOGIN"
gradle test -DCucumber.filter.tags="@...
0
votes
2
answers
21
views
How to unit test the intercept method of a RecordIntercept interface from Kafka using Mockito
I have the class KafkaRecordInterceptor which implements the interface RecordInterceptor<String, Message>
as follow
@Component
public class KafkaRecordInterceptor implements RecordInterceptor<...
-1
votes
0
answers
25
views
Junit Test Case of a method which returns Object and Gets converted to byte array
I have method
public String processIndividualBinaryFile(PhoenixRequestData data, Object attachObj,
Map<String, String> pkgDefnRowData, JSONObject dataObj){
//some code
byte[] ...
0
votes
2
answers
80
views
How to mock private method when I am testing public method in JUnit 5
How to mock private method when I am testing public method in JUnit 5.
class School{
@Autowired
private SchoolRepo schoolRepo;
private String getSchoolName(String name){
return &...
0
votes
0
answers
14
views
how to mock errorDecoder
I have a class in my bff to decode errors from backend. Everything works fine, but I'm having trouble with unitTest in default case.
My class have some part to get the error, that is not relevant for ...
1
vote
1
answer
40
views
junit 5 code/configuration reuse. should i use abstract test class or an extension?
junit 5 docs is using AbstractDatabaseTests
but i remember recommended way for junit 4 was to use rules rather than extending classes.
0
votes
1
answer
64
views
How do I mock a method in another Service in Spring Boot
For context, I have 2 Service classes: ValService and AppService.
In ValService I have a method validatewhich calls a method in AppService:
Character c = appService.sendToAPI(listOfString, stringId);
...
0
votes
0
answers
21
views
Quarkus using Apache Camel: MockEndpoint not working
I am using Apache Camel with Quarkus and I have some @QuarkusTest that use @MockEndpoint that stop to work after I upgraded from camel quarkus 2.7.0 to 2.16.0.
The tests look like:
@QuarkusTest
@...
0
votes
0
answers
25
views
Cucumber-jvm - Thread created per scenario, despite fixed.parallelism being set [duplicate]
Using cucumber-java 7.90 and JUnit 5, setting my junit-platform.properties file to the below, I would expect only 5 threads to be created.
cucumber.execution.parallel.enabled=true
cucumber.execution....
0
votes
1
answer
33
views
Mockito's reified mock method typing the mock as the superclass instead of generic type
I want to provide a simpler interface (utility method) to mock a construction of a class we often need mocked in many tests because it's constructed by a third party library. This class is generic ...
-2
votes
1
answer
41
views
Junit 5 : Testing if condition involving private property in controller
I'm trying to write a Junit test for the following controller:
@Value("${custom.properties.list}")
private List<String> stringList;
final DataService dataService;
@PostMapping(&...
0
votes
0
answers
34
views
Why is my Eclipse hanging at 45% while running the JUnit coverage. I am using JUnit 5 and Mockito
I am using Eclipse to develop a large Spring Boot (Gradle 6.3) project (dozens of dependencies). And having controllers and different util files When I try to run a unit test, the status shows "...
0
votes
0
answers
26
views
Junit5 Optimistic locking exception
I have nearly 1000 test classes coded using spring boot junit5. These run in parallel on Jenkins. Since my 6 test classes use the same table, I am getting optimistic lock errors and I could not find a ...
0
votes
1
answer
44
views
junit spring boot parametrised test not working
I have a basic test set up with paramters
@ParameterizedTest
@MethodSource("intsTest")
public void multiplesOf5(Integer input){
int i =0;
}
private static Stream<Arguments> ...
0
votes
1
answer
30
views
Testing SpringBoot @Cacheable functionality
I've implemented Cache for some DDBB access on a Spring Boot application.
So far it's been working, but we want to ensure it's not disabled in the furture, so I want to add a JUnit test to assert it ...
-2
votes
0
answers
53
views
How to create junit test cases for try catch block where it is called void method
Here is my code
public void listen(String request) {
log.info("received incoming req {}", request);
if (isNull(request)) {
log.warn("Received message is null&...
0
votes
0
answers
14
views
junit platform console "--classpath DIR/*" doesn't work
So I have been trying to use intelliJ coverage agent "intellij-coverage-agent-1.0.735.jar" to generate a report for test coverage same as intellij's results. To execute the tests I have to ...
0
votes
0
answers
54
views
@SpringBootTest with WireMock fails in GitLab CI pipeline but passes locally
The following is a simplified version of a @SpringBootTest which spins up a RabbitMQ container using Testcontainers.
The basic workflow to be tested is:
Send a message to the target queue.
Reject the ...
1
vote
1
answer
40
views
UnitTest final UUID changes within the test if @BeforeEach#repository.save() is executed
I have an OrderRepositoryTest code below where I am trying to get the valid order by Uuid
OrderRepositoryTest
@DataJpaTest
@ExtendWith(SpringExtension.class)
@AutoConfigureTestDatabase(connection = ...
0
votes
0
answers
23
views
Resolve JUnit5 MultipleAssertions / assertAll( ) in JGiven-Testreport
I'm using JGiven and JUnit5 for automated Software tests.
The Then-Stage I'm currently using, asserts a stream like so:
assertAll(executableList.stream());
which works great, but in the JGiven ...
0
votes
1
answer
31
views
privateKey in keystore is returning null
public static PrivateKey getPrivateKey(KeyStore keystore, String keyId, char[] keyPwd) throws BenefitsException {
PrivateKey privateKey = null;
try {
if (keystore == null || keyPwd == null || ...
0
votes
0
answers
31
views
How to isolate subsequent Camel Spring-Boot test suites
I want to test my Spring-Boot/Camel application (Camel 4.1, Spring-Boot 3.1.5, JUnit5), which includes a Kafka consumer, or a producer, or both. I have written several JUnit test suites. When I run ...
-1
votes
0
answers
18
views
Keystore (privatekey) returning null in junit
i'm new to junit5 ,i want to write test method for this below method but in test method the private key returning null despite providing values i don't know what sort of exact values do i need to ...
0
votes
0
answers
62
views
Cucumber class ignored classparh for local runs. All test runs
Test project environment:
java 17
junit5
cucumber7
maven 3.3.9
Runner class:
@Cucumber
@IncludeEngines("cucumber")
@SelectClasspathResource("project/uss/as/play/test/features/smoke/...
0
votes
1
answer
183
views
How to inject Spring beans into a JUnit Jupiter ExecutionCondition
I have custom Interface "Platform" with @ExtendWith annotation and Class which implements ExecutionCondition.
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType....
0
votes
1
answer
42
views
Mockito.eq(1) sending value as 0 to the function
I am testing the below method using the JUnit and Mockito framework.
public Business updateBusiness(BusinessRequest businessRequest, Long businessId) {
String fileURL = fileStorageService....
0
votes
1
answer
61
views
Repository is not being mocked JUnit5 [duplicate]
I'm encountering the following error when I run the unit test:
Error:java.lang.NullPointerException: Cannot invoke "com.example.gerenciadordetarefas.repository.task.TaskRepository.findById(Object)...
0
votes
0
answers
19
views
Maven Junit5 Security Vulnerabilities
5.4 version of junit5 (https://mvnrepository.com/artifact/io.wcm/io.wcm.testing.aem-mock.junit5/5.4.0) which is currently latest version has internal dependency to io.wcm.testing.aem-mock.core version ...
0
votes
1
answer
32
views
Why is the test "test_inputstream..." succeeding, shouldnt it be failing?
package com.skilldistillery.lordo.app;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
import org....
0
votes
0
answers
18
views
Spring Boot RestTemplate call in test class doesn't work in second method
This is my RestUtil class
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org....
-1
votes
0
answers
16
views
how to mock an exception for compatable future for whenComplete in the below code in junit5
Below is the code for publishing a message on mqtt broker:
mqtt5Client.publishWith().topic(topicName)
.payload(messagePayLoad)
.qos(mqttQos)
...
0
votes
1
answer
13
views
Unable to use JUnit 5 automatic extension registration
I'd like to use automatic extension registration, but for some reason the extension does not kick in. If I register it declarativelly: @ExtendWith(SomeExtension.class) it works. So extension tiself is ...
0
votes
0
answers
13
views
Junit5 methods are not running in parallel
I am using Junit5 and have a bunch of test classes (approx 5) each having a few methods (approx 10). I want to run all of them in parallel i.e, in 50+ possible threads. I have done the following ...
0
votes
3
answers
76
views
Spring Boot JUnit5 Mokito when thenReturn not working
UPDATE
Weirdly my test is passing when I am setting String token = "" instead of String token = null in my controller.
Mokito is returning the default value null instead of OK string. So my ...
0
votes
0
answers
36
views
Unable to test Redis repository with @DataRedisTest annotated test class
I'm trying to write unit test for Redis repository of my spring boot application. But the autowired repository object causes the exception below when I run the test case:
org.springframework.beans....
0
votes
0
answers
104
views
Serenity report shows 0 tests run with JUnit 5 and Cucumber 7
I am trying to convert a Java test project from JUnit 4 to JUnit 5. I'm using Cucumber 7 for running some dummy feature files and Serenity for generating fancy reports.
Using JUnit 4 everything worked ...
0
votes
1
answer
52
views
Reusing Cucumber SpringBoot Tests for local and remote integration tests
I have below setup
Springboot v3.x
Cucumber v7.x
Junit v5.x
Maven v3.x
I am able to run cucumber test with below configuration to test SpringBoot Application running locally using maven failsafe ...
0
votes
3
answers
113
views
How to test a void method in JUnit
Since it is mandatory that I have to write test in my company, we have to write Unit Tests for every method that can be tested.
My problem now is that I have a method which has the return value
void ...
1
vote
1
answer
87
views
Configure parallelism on features and scenarios level in the same time - cucumber with Junit5
I checked some similar questions, but did not found an answer for mine. The most similar question was this question, but it's for TestNG. May be somebody faced an issue like me and solved it already?
...
0
votes
0
answers
20
views
Maven Javadoc No source files for package with my test directory structure
I have a small open source project on github TemplateEngine where maybe my test directory structure is a little bit special at the moment:
test/java/de/powerstat/templateengine/
test/java/de/...
0
votes
2
answers
88
views
Junit tests are failing but my methods seems fine in Java assignment
I'm working on an assignement that's due next week
So basically I have a class User with the following attributes
private String userName, password;
private final Instant registrationDate;
private ...
1
vote
0
answers
36
views
Is there a way to run tags as individual tests?
I have a package in my src/test/java directory called com/example/alan/test. Inside that package I have my KarateTest.java file and a features directory, which is full of .feature files. Each ...
0
votes
0
answers
27
views
How can we compare 2 different Exception Objects?
I need to compare a user-defined exception object with Exception class, which is the superclass of my user-defined exception. I used below code but getting error as below :
private String ...
0
votes
1
answer
105
views
Adding JUnit test suite to a Spring MVC application
I want to add JUnit test suite to an already up-and-running spring mvc application.
In particular I want to test the Controllers APIs.
Is there a particular procedure you can recommend?
I dont' want ...
1
vote
1
answer
42
views
Mock JUnit not detecting any sonar coverage for a method that returns string
I am trying to mock below method with the intention of having sonar coverage -
public String getName(String prmTableName) {
GetParameterRequest parameterRequest = new GetParameterRequest();
...
1
vote
1
answer
37
views
Junit 5 not detected
so, i'm trying to create a unit testing with Junit 5, but for some reason the test event were not received. I already removed Junit 4 from gradle dependencies.
import org.junit.jupiter.api.Assertions
...
0
votes
0
answers
25
views
Selenium executes parameterized tests in parallel in the same browser tab
I have parameterized test methods that I want to run in parallel. But when I execute my test class - I see that two browser tabs are opened but only one of them is used by tests to interact with page ...
1
vote
1
answer
36
views
Number of passed/failed parameterized junit test method executions
I have a junit5 test class with several parameterized (integration) tests. Most tests use a MethodSource which can produce a different amount of Arguments depending on external factors.
When I run the ...