28,038 questions
-3
votes
0
answers
63
views
What additional JUnit tests could improve coverage for a QuaternaryNumber class in Java? [closed]
I've implemented a QuaternaryNumber class in Java that represents numbers in base 4 (quaternary system). The class extends Number and supports arithmetic operations like add, sub, mul, div, and ...
1
vote
0
answers
22
views
Trouble with jacoco on apache ant
I have configured my ant target as
<target name="test" depends="build">
<echo message="----- TEST STARTED -----" />
<mkdir dir="${test.classes....
0
votes
0
answers
78
views
Unable to control number of threads with Junit 5 and Cucumber 7
I have been working fine with junit 4 which has maven sure fire plugin working from ages with cucumber 7. But due to deprecated features in Junit 4, cucumberOptions are no longer available or shows ...
Advice
0
votes
5
replies
118
views
How to Test Builder Pattern that Returns an Object with No Accessors?
I have a fairly standard Builder that returns a Command...
Builder:
@Component
@Scope("prototype")
public class CommandBuilder {
private final Repository repository;
private String ...
0
votes
1
answer
49
views
Ways to implement sniffy for junit 6
When setting up connection testing with JUnit as descibed in the docs, I get the error that @Rule can't be resolved to a type, and from what I've gathered off of the internet, @Rule is no longer a ...
0
votes
0
answers
49
views
How to set maven surefire listener from command line
I configured a custom JUnit4 RunListener as below and it works.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</...
3
votes
2
answers
3k
views
java.lang.NoSuchMethodError: 'java.lang.String org.junit.platform.engine.discovery.MethodSelector.getMethodParameterTypes() for JUnit test
I try to devise an example of Spring Boot with using Redis running on Docker. After implementation is over, I try to write some tests. When I run any test instead of running all tests , I got this ...
-3
votes
1
answer
94
views
Unable to mock the repository class object inorder to test the Rest API
I have controller class (ApiController) where service class is autowired (ApiServiceImpl implements ApiService) and where in service class repository class is autowired (ApiRepositoryImpl implements ...
0
votes
0
answers
48
views
Payara 7.2025.1 + payara-micro-managed + Arquillian + JUnit 5 - tests always pass outside container
I’m using Payara 7.2025.1 with payara-micro-managed, Arquillian, and JUnit 5. When I run my tests, a Payara Micro instance starts and deploys correctly, but it seems that the tests themselves are ...
0
votes
0
answers
95
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
0
answers
47
views
@ParameterizedTest with @DatabaseSetup and @ExpectedDatabase
I have the following integration test which is setting up the database with @DatabaseSetup and checking that after doStuffThatAffectsTheDb() executes, the db has been modified as expected with @...
3
votes
1
answer
327
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 ...
1
vote
1
answer
183
views
Does adding opens configuration in maven surefire plugin effect anything outside the test scope?
I'm working on a user-related service that handles personal information. While writing unit tests with Mockito, I ran into dependency issues with Byte Buddy, which prevented me from using the latest ...
1
vote
0
answers
110
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 ...
1
vote
0
answers
111
views
AGP 8.13.0: “6 files found with path 'META-INF/LICENSE.md'” error, can’t define packaging block
I’m using the latest version of Android Studio (Narwhal | 2024.3.1 Patch 3) with Android Gradle Plugin 8.13.0, and I’m getting the following error when building my project:
6 files found with path '...
0
votes
1
answer
339
views
wiremock AutoConfigureWireMock HttpHostConnectException: Connection refused
@ActiveProfiles("it")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(classes = ServiceApplication.class)
@AutoConfigureWireMock(port = 0)
@...
1
vote
1
answer
98
views
How do I rollback database changes only after all tests are run?
For my JUnit 4 tests, a handful of database inserts have to be performed by code. However, the application framework has some overhead, which makes this step really slow.
To save time, I tried to run ...
0
votes
0
answers
37
views
Integration test for a mobile app connected to firebase firestore
I have a mobile application built with Kotlin and linked with firebase firestore, I have a 'LoginOnline' method which call Firebase Authentication to check the user credentials.
I need to know how to ...
0
votes
1
answer
138
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
0
answers
57
views
MockitoJUnitRunner Don't init mocks in SpringBoot
I have this Junit test:
@RunWith(MockitoJUnitRunner.class)
class NotificationServiceTest {
private static final Long EMAIL_ID = 1L;
private static final Long ORGANISATION_ID = 1L;
private ...
0
votes
0
answers
39
views
How to get individual time for test methods when the test class times out (only class-level timeout info shown, need to identify slow test methods)
I am working with junit tests and I have a timeout on them (300s). But when the test timeout I get the information on class level. But I want information on individual test method on how much time it ...
-2
votes
1
answer
72
views
Mock constructor of FileWriter
Trying to mock a constructor of FileWriter so that I can test the catch block. Here is my sample code:
public void write01() throws IOException {
BufferedWriter bufferedWriter = null;
try {
...
2
votes
1
answer
96
views
How do I run java test suites in parallel with Gradle
I'm using the relatively new test suite plugin from Gradle: https://docs.gradle.org/current/userguide/jvm_test_suite_plugin.html.
I assumed that the different test suites, including the default test ...
0
votes
1
answer
152
views
Testing with mockito and junit in java not running
I´d been running tests for my application with mockito and junit and they were fine, but all of a sudden, the tests stopped working without any error message, the tests appear in the left botton ...
0
votes
2
answers
182
views
@DisabledIf with jUnit depending on a string value in application.yml
I need to disable some unit tests depending on a string variable defined in my src/app/test/resources/application.yml.
ENVIRONMENT: local
I'm using Spring's @DisabledIf which takes a single ...
0
votes
0
answers
18
views
Unable to import amazon.awssdk classes in Junit test
I am facing difficulty in running Junit test cases. I am writing a test case for startUpdateRootEmailAddress.
After adding below statement:
import software.amazon.awssdk.services.account.model....
0
votes
1
answer
258
views
h2 db is empty on testing
I want to run tests on my app using h2 as a database but every time I attempt to run a test it shows me an exception saying that h2 db is empty. None of the related questions I`ve read helped me.
This ...
0
votes
1
answer
59
views
Database field error when launching SpringBoot integration tests with maven command (using PostgreSQLContainer)
I have this situation with my Spring Boot application and the management of tests:
The application is running correctly. But for its unit tests, regular tests are OK, while integration tests are ...
0
votes
0
answers
43
views
junit-standalone-console-platform problem with application.properties
I have a problem with reading application.properties by @SpringBootTest when I start it with a command:
java "-Dfile.encoding=UTF-8" "-Dallure.results.directory=config/reports/allure&...
2
votes
3
answers
374
views
junit import not working in IntelliJ IDEA
I have this import in intelliJ IDEA:
import static org.junit.jupiter.api.Assertions.*;
and it says
cannot resolve symbol 'api'
package com.programming.techie;
import static org.junit.jupiter.api....
0
votes
1
answer
106
views
Should JUnit tests crash instead of failing? [duplicate]
I'm writing a small app and have encountered the following issue:
@Test
public void givenSkiExists_whenAddingNewSki_thenThrowEntityAlreadyPresentException () {
skiManager.addEntity(new Ski(new ...
1
vote
1
answer
62
views
Annotate JUnit @Test case with custom aspect annotation
Spring beginner here.
I am making two custom annotations @Satisfy and @Verify, meant to be used to track
requirements in code.
@Satisfy denotes where the requirement is implemented
@Verify denotes ...
1
vote
2
answers
102
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<...
1
vote
2
answers
252
views
Simplify mocking dependencies with @InjectMocks
In my Spring Boot app, I have some tests that look like this
@ExtendWith(MockitoExtension.class)
class InviteServiceTests {
@Mock
private UserService userService;
@Mock
private ...
-3
votes
1
answer
508
views
How to JUnit Test Asynchronous CompletableFuture.runAsync code?
I want to test a method which asynchronously calls an API. Somewhat like below -
private void callExternalAPI(){
CompletableFuture.runAsync(() -> {
try{
//Calling the API
}...
1
vote
1
answer
130
views
How can I share @BeforeTest and @AfterTest setup logic from commonMain in Kotlin Multiplatform?
I'm working with Kotlin Multiplatform in a multi-module setup. I want to create a dedicated module that defines reusable test setup and teardown logic—similar to JUnit rules—in the commonMain source ...
0
votes
1
answer
45
views
How to go for JUnit testing for producing the test cases for the given program?
Suppose if you are going for the creation of test cases in VS code then how to build the test file for that by commands or built-in options ?
2
votes
1
answer
1k
views
Ignore IntelliJ warning "closeable used without 'try'-with-resources statement"
I have a junit test suite which uses some AutoCloseable resources, which I take care of closing after all the tests has been executed using org.junit.jupiter.api.AfterAll annotation, see the example:
...
-1
votes
1
answer
53
views
How to test an API which has Oauth2 Resource Server
I got some problem with Junit (Spring Security 6.5), I have an API Register to testing which already work well when test with Postman (fully output), When test with Junit, I got test fail with error ...
9
votes
2
answers
6k
views
Cannot build project after upgrading Spring Boot to 3.5
I cannot build my project after upgrading Spring Boot from 3.4.6 to 3.5
When I try to, Gradle says there were failing tests:
Execution failed for task ':core:test'.
> There were failing tests. See ...
0
votes
0
answers
58
views
Hibernate Shared Sessions
Since I migrated to Hibernate 6.x+ I started having problems with shared sessions in unit sessions.
I have a problem where I have the following structure:
I have a test that first creates a record (...
1
vote
0
answers
95
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
1
answer
163
views
When performing integration tests for Springboot app with RestTemplate, why are not all returned values set?
I have a Springboot API that includes a model class Payment, a @Service class PaymentService, as well as a JPA repository, controller, and some utility classes. I have integration tests that mostly ...
0
votes
0
answers
46
views
Hibernate/JPA Not Throwing Error on Delete with Foreign Key Constraint
I'm trying to write some unit tests for a many to many relationship with an association table with a couple extra columns. Realistically if I try to delete an ingredient and then flush the db it ...
2
votes
1
answer
84
views
ResourceBundleControlProvider not invoked when running program in an unnamed module under JUnit
When running a test program in an unnamed module under JUnit the ResourceBundleControlProvider.getControl() method is not invoked.
I have this implementation of ResourceBundleControlProvider:
...
0
votes
0
answers
38
views
initializationError - Error- No runnable methods
I am running my 2 test suites using Ant build, both contain arround 30 test cases.
In the error it not giving any information which test case making this issue. I run with detaled log (-v option) and ...
0
votes
0
answers
60
views
No constructor in tested class that can be satisfied by available tested/injectable
Goal:
TC need to pass
Using:
junit 4.12
jmockit 1.54
Adopt JDK 21
test case Code:
public class UTBOMRetrievalDAO {
@Tested
BOMRetrievalDAO bomRetrievalDAO;
@Injectable
ServerContext ...
0
votes
1
answer
68
views
Maven build result is not showing as expected
I have a cucumber suite project which runs on top of Junit. I have updated the version from junit 4 to 5 and cucumber 4 to 7 both are BOM dependencies. In Junit-4 I was using cucumber-jvm-parallel-...
0
votes
1
answer
320
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
...
0
votes
1
answer
62
views
Calling a method on the object returned by CrudRepository save() method
I am trying to write a JUnit test for a relatively basic class that is responsible for persisting an object with a Spring Data CrudRepository, then extracting the generated ID from the object and ...