4,148 questions
3
votes
1
answer
328
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 ...
2
votes
1
answer
85
views
Why @Transactional method does not behave as expected in tests?
I'm testing that:
@RunWith(SpringRunner.class)
@DataJpaTest
@Import({ OrderService.class, UserService.class })
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class ...
0
votes
1
answer
60
views
Can't verify that in anonymous inner class method throw exception
Given:
Java 8
Mockito 4.3
Junit 4.11
Here my java code:
public interface ClientListener {
void addClientStatusListener(StatusListener statusListener);
}
@FunctionalInterface
public interface ...
0
votes
1
answer
157
views
java.lang.NoSuchMethodError: org.mockito.invocation.InvocationFactory.createInvocation(Ljava/lang/Object
Java 8
Maven 3.9.
I want to verify is void private method call.
I try PowerMock.
pom.xml
<properties>
<powermock.version>2.0.2</powermock.version>
</properties>
...
0
votes
1
answer
173
views
kotlin.test.BeforeTest is not resolved
After updating Android libraries (including Kotlin) I found that @BeforeTest became unresolved (@Before is resolved, it belongs to org.junit).
import org.junit.Before
import org.junit.Test
import org....
-1
votes
1
answer
570
views
Cucumber and gherkin feature test with error No matching tests found in any candidate test task
gradle failed to find my test. already switching between JUnit too and its still not fix it, and it still give same error as its not found. i tried everything to find a way to look for solution but no ...
0
votes
1
answer
693
views
Maven Surefire Plugin Configuration with JUnit5 and TestNG Failing
I currently migrated a project from JUnit4 to JUnit5. The test classes are a mixture of JUnit and TestNG. My current maven plugin is written in the parent POM like:
<!-- https://mvnrepository.com/...
0
votes
2
answers
428
views
SpringBoot 2.7.18 with H2 DB
I Have an SpringBoot 2.7.18 with H2 2.3.232, with this SQL for testing:
CREATE TABLE IF NOT EXISTS EXERCICE
(
EXERCICE_ID NUMBER AUTO_INCREMENT,
TYPE_SITE_ID NUMBER,
...
0
votes
0
answers
69
views
Why am I getting NoClassDefFoundError even after having the class in testing in Android Studio
I'm trying to test my Helper class which is a Kotlin class in Android Studio. I've JUnit dependencies as it is that I get with new Project creation. But, whenever I try to run test, I get ...
1
vote
0
answers
104
views
Can't write a good test for service layer in java application
I've tried to make some tests for Service layer in my java project. The test supposed to simply mock adding a new patient to database. After constantly failing, I simply gave up, and came here for ...
1
vote
1
answer
191
views
ApplicationContext not loading in Junit 4 test case after upgrading to spring-boot v3.2.10
This used to work in spring-boot v2 but after upgrading to spring-boot v3 test case gives error. The @Value annotation is not picking the right value from application.properties file because the ...
0
votes
0
answers
50
views
Mocking Cache Config class failing
I haven't mocked the configuration class for cache config properties. Can someone help me with possible unit tests for this cacheable layer ?
CacheConfig.java
import com.github.benmanes.caffeine.cache....
0
votes
1
answer
140
views
How to write a tests for PickVisualMediaRequest, in android studio?
I have a fragment in my app that requests the user to upload an image. How can I write a Junit test that runs on the emulated device that would select and image from the pop up? I am also wondering if ...
0
votes
0
answers
244
views
JUnit 5 + Mockito tests are significantly slower compared to JUnit 4 – how to optimize?
I'm migrating our tests from JUnit 4 to JUnit 5, and I'm noticing a substantial increase in execution time for tests using Mockito. Specifically, empty tests take almost 100 times longer with JUnit 5.
...
1
vote
0
answers
69
views
Mockito Exception for mocking interface HttpServletRequest
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: interface javax.servlet.http.HttpServletRequest.
Mockito can only mock non-private & non-final classes.
If you're not ...
0
votes
0
answers
56
views
(Android Studio Tests) Error: Could not find or load main class Files\NVIDIA
I'm developing an application in Android Studio for Windows.
When attempting to run one of the JUnit4 tests I've created, I get this error:
> Task :app:testDebugUnitTest FAILED
Error: Could not ...
0
votes
0
answers
120
views
Tests broken for IntelliJ Spring Service after updating dependencies - legacy code
I have a legacy Spring Service that I am trying to update to remove a log4j vulnerability.
I have updated the relevant dependencies/code and my project builds, compiles and runs successfully.
However ...
0
votes
0
answers
95
views
JUnit test suite @IncludeTags is also running JUnit4 tests without @Tags
I want my test suite to only run the @Tagged tests and ignore the ones annotated with @RunWith.
I have JUnit 4 and 5 tests. I have a test suite that uses @IncludeTags("myTag"). I have JUnit5 ...
0
votes
1
answer
58
views
Unit-tests exhibiting 'state' across test-methods after moving from JUnit4 to TestNG
The legacy project I'm working on uses both JUnit4 and TestNG testing frameworks and for reasons beyond my control I cannot upgrade to JUnit5.
While all new test-suites (classes) that we create are ...
3
votes
0
answers
170
views
I want to understand test result format of Junit in VS Code
In VS Code, using JUnit. I am testing addition() method of calculator class. I have used assertEqual method to compare expected result and actual result.
This is my code for test method:
@Test
...
0
votes
0
answers
162
views
How to test a Quarkus application with JUnit 4?
I’m porting an application to Quarkus, and am now updating its tests to use Quarkus as well.
I could port successfully the JUnit 5 tests using @QuarkusTest and @TestHTTPResource:
package com.example....
0
votes
1
answer
244
views
Is there a replacement for assumeThat in JUnit 5?
I am migrating code from JUnit 4 to JUnit 5. Is there any replacement for the method Assume.assumeThat?
1
vote
0
answers
181
views
execution failed for task ':app:connecteddebugandroidtest
My instrumentation test is not executed in the device after the test and app install. The test sometimes keep "building" for long times +15min
Here is the logcat with warnings and info ...
-1
votes
1
answer
78
views
Unit test for Lambda expression
I am trying to write a unit test (using Mockito) for my Spring Security config class and it has this code
@Bean
public GrantedAuthoritiesMapper authoritiesMapper() {
return (authorities) -> {
...
1
vote
0
answers
44
views
how to spy/argumentcaptor of background thread to verify in karate-spring boot application
I've a scenario, API service running in springboot and trying to port the existing functional Test to karate based testing. I've added. the API endpoint based configuration and other validation for ...
0
votes
1
answer
53
views
NoMatchingViewException error during Espresso test
I am doing an instrumentation test of Fragment is displayed or not. When I start the test it execute, I am able to see FragmentLogin view in physical device but test fail by saying androidx.test....
0
votes
0
answers
55
views
How to write test cases where the mocked objects are not giving anything back
How to write assert or verify for these. I cannot change the code in any way. Only Junit can be written by me.
public void Calculator(booker, product) {
Matcher matcher = buildCriteria(product);
...
0
votes
1
answer
65
views
JUnit 5 - Migration - Custom test annotation no longer detected?
I had the following custom test annotation that worked in JUnit4 that IntelliJ and JUnit no longer wants to recognize:
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RUNTIME)
...
0
votes
0
answers
53
views
Maven Test runs indefinitely on a Test Suite which executes fine in Junit4
I recently mavenized few old projects. When I am trying to build caffeine tests project with maven build, the test suite hangs when it executes the first test.
I debugged the application, it adds all ...
0
votes
0
answers
47
views
How can i check that exception was thrown and handled in Junit4/Mockito?
I'm writing tests using Junit4 and mockito and wondering if there is a possibility to check if specific exception was thrown and handled inside tested method.
What I mean is - I have for example ...
1
vote
0
answers
67
views
How to mock a final class to do nothing when a method from a final class is called using Mockito?
How to mock a final class to return nothing when a function from a final class is called?
In test method:
@InjectMocks
CustomerService customerService;
@Mock
AddCustomerProfile addCustomerProfile;
@...
0
votes
1
answer
161
views
Error occurred prior to updating JUnit 4 to JUnit 5
Before the update, don't run my class RunTest, get a error in execution
package automation;
import org.junit.FixMethodOrder;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
...
0
votes
0
answers
88
views
How to throw exception with super constructor been mocked
I have an exception class
public class FooStudioException extends SpamException {
public FooStudioException(String message, String localizedMessage, Throwable cause) {
super(...
1
vote
0
answers
207
views
Mockito.mock(...) does not work inside an Arquillian integration test anymore
We're upgrading from Java 8 to 21 and since we run Arquillian with a remote Wildfly for integration testing, but also have some mocking inside those test classes to avoid to execute some annoying code,...
0
votes
1
answer
33
views
fill @value variable in a test
I want to test this KeyStoreConfig class but what ends up happening is jceksFileLocation is always null and returns an error What can I do to test this class thoroughly. If I could somwhow populate ...
0
votes
1
answer
55
views
getInputStream() of a mock Socket returns a null object
I'm writing a junitTest that should test a serverHandler object that handle the reciving and sending of message to a server.
I'm doing that by mocking the socket of the server and putting my own ...
0
votes
1
answer
58
views
How can I control which class will be inject using @AutoWired when writing unit tests?
I have a class like below
class Foo{
@AutoWired
private Bar bar;
@AutoWired
public Foo(List<Baz>){
// do something with Baz
}
how can I control which Baz will be injected, like only ...
0
votes
1
answer
83
views
Selenium WebDriver used to open chromium with `mvn test`, but does no more
I started a Selenium + JUnit 4 Test from the two getting started documents.
I am on Maven3, Java17 and IntelliJ IDEA w/ Arch Linux.
My pom.xml is as follows:
<?xml version="1.0" encoding=&...
1
vote
1
answer
517
views
How can I mock a super class and suppress calls to the actual super class constructor using mockito-inline?
I've seen some old questions about using the regular mockito mock maker. i.e. using the mockito-core dependency. I think this is not a duplicate because I'm using the new inline mock maker from ...
0
votes
1
answer
105
views
Is it possible to specify multiple annotations into the --test-targets command
According to the firebase documentation I should be able to specify multiple test target filters - https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run#--test-targets
I've specified ...
0
votes
0
answers
38
views
Android: Junit test to check/validate file inside Assets folder throw FileNotFoundException
I have abc.json file inside Assets folder of the Android project.
Everything is working in the application. i.e, able to read this file when launching the app on the phone.
Junit test to validate the ...
0
votes
0
answers
320
views
Failing to load ApplicationContext for @DataJpaTest
I have a Jhipster project that uses spring boot 1.5.12.RELEASE and I want to add tests for the repositories using @DataJpaTest. There are also some ITs in the project without @DataJpaTest and ...
3
votes
2
answers
992
views
Unit Testing StateFlow Created By StateIn
I have a viewmodel class that uses a StateFlow that is created using the StateIn operator.
I.E.
private val _state = MutableStateFlow(MyState())
private val myItems = myRepository.myFlow.stateIn(
...
0
votes
0
answers
55
views
How to test a Spring method for adding a file to GridFS with JUnit and Mockito?
public String addMaquette(MultipartFile maquette, String keySousRubrique, String projectId, String titrePage) throws IOException {
DBObject metadata = new BasicDBObject();
metadata.put("...
0
votes
1
answer
2k
views
trying to run in parallel for cucumber junit not working
I added the parallel and threadcount lines to surefire plugin configuration in pom file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-...
0
votes
1
answer
146
views
Junit with Mockito for java
I am learning java and exploring junit with Mockito.
The idea is to understand where and how to use mockito and learn how to write junit tests. Im a beginner and learning.
How can i write a junit test ...
0
votes
1
answer
54
views
Testing ProtoDatastore with JUnit4
I have a repository class that works with a Proto DataStore I have defined that is NOT the Preference DataStore equivalent. My proto file looks something like this:
syntax = "proto3";
...
0
votes
0
answers
536
views
restDocs requestParameters cannot find
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
User
java: cannot find symbol
symbol: static requestParameters
location: class org.springframework....
0
votes
1
answer
82
views
Run instrumented test inside module's androidTest
Is it possible to run an instrumented test in an Android module that has no activity but uses AppCompat dependencies? I am attempting to run a simple test but only works if moved to app module.
Util ...
-1
votes
1
answer
335
views
@MockBean does not get mocked when using @DataJpaTest
Env:
2 datasources - one PostgreSQL and MongoDB
JDK 17
Spring Boot 3.1.1
JUnit 4
eventRepository is not returning mock when called by updateScheduler Service for @DataJpaTest.
Everything bellow works ...