3,803 questions
1
vote
1
answer
258
views
DataJpaTest and AutoConfigureTestDatabase in Spring Boot 4.0.0
I have the following errors using Java 17 with Spring Boot 4.0.0:
Cannot resolve symbol 'DataJpaTest'
Cannot resolve symbol 'AutoConfigureTestDatabase'
The problem happens in a JUnit test class ...
1
vote
1
answer
39
views
Multiple instances of test class using Weld-JUnit5
I have "simple" Junit5 Test which I would like to run with Weld.
The test fails, because observer method is invoked on other instance of test class as the one which was started. Even thou I ...
0
votes
0
answers
54
views
Mockito MockStatic behavior leaking to other junit tests
I am using Mockito 5.20.0 to mock a static method, but the mock is not correctly closing / the mocked behavior is leaking outside of the tests it is intended to apply to. This is only a problem if ...
2
votes
1
answer
118
views
How to control test class execution order in JUnit 5 suites?
I'm organizing my tests using JUnit 5's @Suite and @SelectClasses, but need to control the execution sequence of the test classes. According to the documentation, @SelectClasses doesn't guarantee ...
0
votes
0
answers
26
views
Missing libraries when executing JUnit4to5Migration with OpenRewrite
When running OpenRewrite on my multi module project (Maven 3.99, Java 21) with this configuration in the root pom:
<plugin>
<groupId>org.openrewrite.maven</groupId>
...
1
vote
0
answers
69
views
Is it possible to run spring boot test using junit console launcher?
I am trying to create a fat JAR that includes my application and its tests to run them externally using the JUnit Console Launcher. The build succeeds, and the JAR is created. However, when I execute ...
0
votes
0
answers
72
views
Junit test case failing
I have a springboot maven project in which I have a very simple class which has a static method which takes in a http client, some configs and an object mapper
This class is under package com.cs....
1
vote
1
answer
89
views
How to configure Gradle to pickup ArchUnit tests via @Tag annotation?
When I tried to integrate ArchUnit into our setup, I noticed that ArchUnit tests were not being picked up by Gradle.
Our Gradle config contains several testing tasks to separate UnitTests, ...
0
votes
0
answers
45
views
Unable to run Junit 5 with Cucumber on AWS Codebuild
I'm in the process of converting my Java Maven repository from Junit 4 to Junit 5. After updating my methods, runner, and POM, I can run the tests locally in Intellij, but when running them on AWS ...
0
votes
1
answer
73
views
How to correct the build path for a JUnit Test Class in Eclipse? [duplicate]
I'm making a JUnit test class for a java class in Eclipse and I'm unsure of what steps to take to fix it.
I tried to add the JUnit 5 Library to the build path as part of "Fix project setup",...
0
votes
1
answer
46
views
Checking if test run in interactive session
How can you make an assumption that checks if a test is executed in an interactive session?
FEST robot clicks and such are ignored on the CI server now since the session is not interactive, but I don'...
2
votes
2
answers
100
views
Asserting on displayed JDialogs
How do I assert on Swing modal dialogs?
The problem:
I can't show a dialog synchronously — it would block the thread indefinitely.
I can pass it to SwingUtilities#invokeLater, but can neither assert ...
-4
votes
1
answer
222
views
Making tests pass if they fail
Related: Rethrowing Throwables from EDT
I want to test my InvocationInterceptor that runs tests in event dispatching thread (EDT).
Among other things, it shouldn't swallow any Throwables. I wrote a ...
2
votes
2
answers
151
views
Writing safe, non-ugly Swing tests
I keep hearing this recommendation to always access Swing components on the EDT, including in tests. In plain Java, it usually means calling invokeLater() / invokeAndWait().
Indeed, some tests do ...
2
votes
1
answer
146
views
Mockito, Java not producing reliable results
I have a Java test class setup with Mockito and get some strange behavior. My class looks as follows:
@ExtendWith(MockitoExtension.class)
public class FrameworkTest {
@Mock private OrderService ...
3
votes
0
answers
88
views
Unit tests for method parameters with NotBlank or similar annotations
Take a @Validated class and a method with a parameter annotated @NotBlank from jakarta-validation-api 3.0.2.
@Validated
public class Foo {
public void bar(@NotBlank String baz) {
}
}
How ...
0
votes
1
answer
105
views
Maven build not failing on failed scenarios [closed]
After days of trying I did not find a way to let the Maven build fail if a Cucumber scenario fails. What am I missing?
Here a minimal example of that build setup. It uses Maven Wrapper to simplify ...
1
vote
1
answer
78
views
CoroutineTestExtension not working when parallel test execution is enabled in JUnit5
I have multi module android project where I am doing junit4 to junit5 migration
For CoroutineTestRule I have added CoroutineTestExtension but it's not working well when parallel test execution is ...
1
vote
1
answer
112
views
Why failed when using mockito3 + powermock2 to mock new object
I am trying to mock a constructor method. But failed with messages said unnecessary stubbings.
What modify should I make to succesfully run this unit test? Plus, Better not to modify the version of ...
0
votes
0
answers
37
views
Moving from Java 11 to Java 17, issues with weld-junit5: NoClassDefFound javax/enterprise/inject/spi/BeanManager [duplicate]
I am trying to move an app from Java 11 to 17. Maven compile goes fine, but if I try to run tests I get a lot of "NoClassDefFound javax/enterprise/inject/spi/BeanManager" errors. I excluded ...
0
votes
2
answers
56
views
How to run tagged tests that are explicitly excluded in pom.xml?
This is part of my pom.xml:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<excludedGroups>slow<...
0
votes
0
answers
63
views
Problem using Koin with Ktor and testApplication in unit tests – KoinAppAlreadyStartedException
I'm writing unit tests for my Ktor 2.3.0 application using Koin 3.4.0 for dependency injection and MockK for mocking. I want to test my controllers using testApplication {} from ktor-server-test-host. ...
0
votes
0
answers
29
views
Shared Lifecycle for Distributed Test Groups in JUnit 5?
Does JUnit 5 provide an inclusion mechanism that allows splitting a test class's methods into groups, distributing each group into separate class files, and then selectively executing some or all of ...
1
vote
1
answer
40
views
Global class to start JUnit 5
for JUnit 5 is it possible to create a class which executed (an object of this class...) before any of the junit tests are executed? In my case I would like to setup some logging before the tests ...
0
votes
1
answer
41
views
Is there a way to test CriteriaBuilder.isFalse() from Spring JPA?
I have a method that creates a Specification (Spring JPA) from my custom object to check if its attribute is False with the method. Using Mockito, I tried do the unit test below.
void ...
1
vote
0
answers
82
views
How to handle test case dependency when one test must use the functionality tested by another
I am trying out unit testing in Java with JUnit for an assignment.
Previously, we were tasked with creating a generic puzzle-solving algorithm using graph searching algorithms.
The important part is ...
2
votes
2
answers
170
views
Testcontainer for Kubernetes and Argo Workflows
I want to do some integration testing + setup local dev environment for a Java/Spring Boot application that interacts with Kubernetes via Argo Workflows. I don't see a Kubernetes test container (...
0
votes
1
answer
189
views
Why the package org.junit does not exist with maven but runs fine in Eclipse?
I have a project that runs the tests fine in Eclipse. If I run mvn verify after Eclipse compiled the project, at first sight it seems to run every test class fine, just runs 0 tests in each of them.
...
0
votes
1
answer
196
views
Repeated parameterized test with JUnit 5 / Jupiter
I want to repeatedly execute the following test class:
class Test {
static Foo foo;
@BeforeAll
static void setUpAll() {
foo = generateRandomFoo();
}
@ParameterizedTest
...
1
vote
0
answers
75
views
Issues when checking documents in embedded test flapdoodle mongodb
I am developing a project and I am now creating junits for parts of my code where I use a mongo DB connection. On my actual DB it works fine but I am trying to set up an embedded DB to run my tests on ...
0
votes
0
answers
54
views
How to populate setter getter methods in a class annotated with @Configuration in Junit Test case
I have created a library using Spring to send message using Kafka Template. I am using the library in Spring boot application. The configuration fields are fetched from application.yml in Sprint boot ...
1
vote
0
answers
322
views
JUnit, Spring Boot 3.4.4: Error creating bean with name 'jpaMappingContext': Metamodel must not be null
I've updated the version of Spring Boot in my project to 3.4.4. And now one of the JUnit tests starts failing with the exception org.springframework.beans.BeanInstantiationException: Failed to ...
0
votes
1
answer
162
views
How to Enable HTTP Sites in Selenium with ChromeOptions for Java?
stack: OpenJDK Zulu21.40+17-CA (build 21.0.6+7-LTS), Google Chrome 134.0.6998.117 (stable), Gradle, Junit5, Fedora 41 (the same thing happened on windows 11)
the problem: I am writing autotests for an ...
0
votes
0
answers
63
views
Cannot resolve method 'thenReturn(LettuceBasedProxyManagerBuilder<String>)'
I have this code which I want to to test with JUnit test:
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.time.Duration;
import javax.sql.DataSource;
import io.github....
0
votes
1
answer
43
views
jUnit Spring Batch 5 [closed]
I have this class:
package com.example.demo;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core....
0
votes
1
answer
75
views
Junit5 Wildfly TestEngine implementation is found via Class.forName but not found using the ClassLoader
I have a WAR deployed on WildFly that depends on a module where JUnit 5 JARs are located. I keep getting this exception:
[Cannot create Launcher without at least one TestEngine; consider
adding an ...
1
vote
0
answers
26
views
Junit issue mocking an implemetation class
I have a class Foo with generics. Inside class Foo, I have an interface declared Bar.
public class Foo<T,U> {
@Autowired
private Bar<T, U> bar;
public Mono<F> calculate(...
0
votes
1
answer
77
views
How to use anyString() inside a Map for Mockito verification?
I'm writing a unit test in a Spring Boot application using Mockito and JUnit 5, and I'm trying to verify a method call where one of the parameters is a Map<String, String>.
Here's the method ...
1
vote
0
answers
368
views
SpringBoot 3 + Junit5 + Cucumber : Junit Runner don't see cucumber tests
I have to start integration testing in a new springboot project and I'm struggle with Junit and Cucumber.
Java 23
Spring Boot 3.4.3
Gradle
Cucumber 7.20.1
Junit 5
I added these dependencies
...
0
votes
0
answers
52
views
Im trying to execute Junit tests in a group project but this error doesnt stop to appear in eclipse console:
Error in question:
I have tried to uninstall and install again eclipse, uninstalled and installed the Junit 5 library, and Restart Eclipse
By the way Im using Eclipse IDE for Java Developers Version: ...
1
vote
1
answer
132
views
How to solve 'Cannot subclass final class java.lang.reflect.Method'?
I have this Junit 5 test code:
@InjectMocks
ReportAssembler reportAssembler;
private ReportingReturnResponse reportingReturnResponse;
private ReturnReport returnReport;
private StaticPathLinkBuilder ...
0
votes
0
answers
27
views
How to control assignment of tests to processes with Junit5 and maven-failsafe in forked execution mode?
Context
Consider a Junit 5 test suite with a maven-failsafe configuration that is configured to run the tests concurrently in multiple processes using the forkCount parameter.
Question
Is it possible ...
0
votes
1
answer
221
views
Spring Boot 3.4 Junit 5 Mockito - Unable to load properties from application-test.yml
I have been trying to write a test using Mockito for my service layer, there are properties required to be loaded from the application-test.yml.
The information is getting loaded in the repository ...
0
votes
1
answer
214
views
Cannot invoke "java.lang.reflect.Method.getDeclaringClass()" because "method" is null in Junit 5
I want to mock a complex case of Java method response into JUnit 5 test which is using hateoas.
The JUnit 5 test:
@ExtendWith(MockitoExtension.class)
public class ReportingATest {
@Spy
protected ...
0
votes
0
answers
33
views
Missing org.codehaus.groovy.runtime.InvokerHelper
I have this old JUnit code:
import static org.codehaus.groovy.runtime.InvokerHelper.asList;
import static org.mockito.Mockito.when;
User user = new User ();
....
when(calculate(any()))
....
0
votes
2
answers
131
views
Mockito: How to make a method return a List?
i am trying to write a service's unit test, which tests the user login method with mockito and junit5. But some objects that should be mocked do not have its value. So it cause a NPE. this is the main ...
0
votes
0
answers
53
views
Multimodule cucumber project
The question is:
Is it possible to use the steps implemented in another module?
Currently, I have a core module with implemented steps (located in core.steps) and a project1 module (conditionally).
In ...
0
votes
3
answers
3k
views
@MockitoBean is null while testing spring boot rest controller
I am trying to test Spring Boot's Rest controller.
Problem:
I am using @MockitoBean annotation for mocking the ContactService.java class. The Rest controller depends on this ContactService.java class.
...
0
votes
0
answers
79
views
Can I Use @QuarkusTest to Replace JerseyTest in Spock Specifications?
I have many Spock specifications like the next one, that act as "unit tests" for the resource classes of a project. This is an Open Liberty application and now there's a need to migrate it ...
0
votes
1
answer
105
views
How to automatically apply SINGLE custom JUnit5 extension to all test classes?
I have a custom junit5 extension, that purpose is to do some clean up after each test class.
I want it to be applied to all test classes in multi-module project automatically.
Problem is when I enable ...