Questions tagged [junit]
Popular unit testing framework for Java and Scala. The latest version, JUnit 5, supports rich annotation-based and parameterized tests. Consider using in conjunction with the Java or Scala tag to indicate your use case.
junit
28,073
questions
1
vote
0
answers
18
views
SpringBootTest with Togglz
I just recently added togglz to the spring-boot 3.1.9 application, which contains also much stuff like spring-security, spring-data, etc.
Maven dependency:
<dependency>
<groupId>org....
1
vote
0
answers
3
views
JerseyTest and Mockito - problem with mocking an object
My aim is to learn a little bit about mocking objects in the context of Jersey Test.
I have 3 classes:
ServiceController
package com.vogella.jersey.first;
import javax.ws.rs.*;
import javax.ws.rs.ext....
0
votes
0
answers
19
views
Dependency not getting mocked in unit test
I am trying to run a unit test for my springboot controller as:
@WebMvcTest(controllers = MyController.class)
@ExtendWith(SpringExtension.class)
public class MyControllerTest {
@Autowired
...
0
votes
0
answers
18
views
ParameterizedTest JUNIT5 with suspend functions
I'm trying to clean a little bit my code and when testing my datasource I'm repeating a lot the test that returns connection and service error, and I'd like to have a bunch of code that tests ...
0
votes
0
answers
10
views
Junit expecting a 400 response but getting a 200
I am trying to test my springboot controller /save endpoint. I want to test that if you send a json request with a null agency name you should get back a 400 status and the response "Agency Name ...
0
votes
0
answers
37
views
Spring Boot microservices with JWT (Cannot run Integration test (401 Unauthorized Error))
I try to implement an example of Spring Boot microservices with JWT. I have some problem. I cannot run all integration tests of product service even if I defined bearer token in terms of admin and ...
-3
votes
0
answers
36
views
IntelliJ IDEA 2024.1.4 (Community Edition) + Mac OS 11.5.2 : Build > "Writing Classes" is very slow [closed]
IntelliJ IDEA 2024.1.4 (Community Edition) + Mac OS 11.5.2
I'm trying to debug JUnit test case but it's observed that "Writing Classes" is very slow.
It takes more than 3+ minutes to start ...
-1
votes
0
answers
49
views
Unit test for a method that does a map lookup [closed]
I am new to Kotlin and I am writing unit test for a method that tries to load a value from a map defined at class level (kind of like a local cache) and returns if the value is found otherwise a ...
-1
votes
0
answers
38
views
doAnswer Mockito: Behaving strange and not verifying the mocked listener [closed]
I am trying to test the API call method, since this API is final I can not extend and create Test Doubles, so I have used Mockito to stub the functionality after initializing this API, I created Test ...
0
votes
1
answer
39
views
Stubbing error while mocking WebClient using Mockito
Based on answers to previous questions like these, I am trying to mock WebClient in a unit test. Please note that I don't wish to use WireMock or MockWebserver.
source method:
public class ...
1
vote
1
answer
32
views
I cant init my webclient in a test with mockito
I'm working on a project with java spring boot 2.x and java 1.8. In my pom i got the dependencies of junit 4.13.2 and mockito 3.12.4. When i try to run my test i got the problem that my setup function ...
0
votes
0
answers
42
views
How to mock Files API from java.nio.file.*
I am using Java nio API and have a below code, but unable to perform mocking on the below code.
Path path = Paths.get(filePath);
long sizeInBytes = Files.size(path);
long recordCount = 0;
try (Stream&...
0
votes
1
answer
23
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
31
views
pytest failing to generate xml correctly
Unable to generate junit xml file correctly, after a failure generation of the file stops and no further tests are executed. The command works without the junit argument. I have also tried adding '-...
0
votes
1
answer
46
views
SimpleAgedCache: Why can't I get my SimpleAgedCache to pass its tests?
I'm new to coding and programming, and I found an interesting SimpleAgedCache exercise on GitHub that uses JavaScript. I feel like I've done the correct coding, and the exercise should pass its tests. ...