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,059
questions
0
votes
0
answers
7
views
JUnit test failing Status expected:<201> but was:<404>
I've spent a lot of time trying to figure out this issue, but when I'm running my tests on my UserControllerTest class I'm getting Status expected:<201> but was:<404>.
Here's my ...
0
votes
0
answers
11
views
How to test flow paging data for an android application?
I'm currently testing repository class in my Android App, the function itself returns Flow<PagingData>. When I run the test it gives an error :
After waiting for 1m, the test coroutine is not ...
0
votes
0
answers
13
views
I'm trying to work testcode about Java Spring Boot 6.x Websocket code with STOMP but in trouble
public class WebSocketIntegrationTest {
@LocalServerPort
private int port;
@Autowired
private MockMvc mockMvc;
@Autowired
private ObjectMapper objectMapper;
private ...
0
votes
1
answer
27
views
Playwright Junit file into X-ray
I am able to generate a results.xml file using playwright execution and also upload to JIRA.
However, my screenshot/video from the execution are not reported back into X-Ray.
I can see in xml file, ...
0
votes
1
answer
42
views
Group (or merge) @Unroll tests from Spock in JUnit XML result file
I have a Spock @Unroll test like this:
@Unroll
def 'A session uses the TLS protocol #enabledProtocolsOfSocket #protocolOfSession'() {
given:
// ...
expect:
// ...
where:
...
0
votes
0
answers
26
views
How to write verify for static methods that have been called [in Mockito Core] [duplicate]
Without using PowerMockito and using Mockito-Core (the version of Mockito doesn't support PowerMockito and I cannot change the Mockito version), How can I verify that a call to a static method has ...
1
vote
0
answers
42
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
27
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
22
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
23
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
13
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
40
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 ...
0
votes
1
answer
44
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
36
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
44
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
24
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
32
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
49
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. ...
-1
votes
2
answers
63
views
How to write a unit test with a controller method that has protected code in it [duplicate]
I am trying to write a unit test for the following controller:
@RestController
@RequestMapping(value = ENDPOINT_URL)
public class MainController extends RestControllerBase {
MainService ...
-1
votes
0
answers
504
views
Test cases failing and getting NoClassDefFound Could not initialize class XXX after upgrading Maven to 3.9.6 version
Test class
`@BeforeEach
public void initResource() {
serviceLocator = mock(ServiceLocator.class);
service = mock(Service.class);
resource = new MappedDefaults(serviceLocator, service);
...
0
votes
1
answer
65
views
Asserting availability of SubTypes of T
I would like to assert whether every element of an array is a sub type of a particular class. So I wrote a helper like this:
private <T> void assertContainsAllSubtypes(
List<? ...
1
vote
2
answers
43
views
Is it advisable to repeat an integration test that is used in more than one method?
I'm developing a project. This project has a repository (UserRepository) which is referenced by other parts of the project, I want to know if I have to test the repository method each time it is ...
1
vote
1
answer
23
views
Java unit test failing due to null KeyHolder
I'm creating new unit tests for an application and I'm stuck because the KeyHolder is not returning a valid object.
For context, here are my classes:
ScriptDao class:
@Repository
public class ...
0
votes
0
answers
11
views
The user is experiencing an error in their Junit program, despite using assert-equals with two integer numbers
I have used the Assert Equals (Expected, Actual) method which takes two integers value and stores its sum in the Actual variable. I am putting my code below.
public class CalcTest
{
@Test
...
0
votes
0
answers
29
views
Junit error Can't load log handler "1catalina.org.apache.juli.AsyncFileHandler"
Getting below error while running junit.
Can't load log handler "1catalina.org.apache.juli.AsyncFileHandler"
java.lang.ClassNotFoundException: 1catalina.org.apache.juli.AsyncFileHandler
java....
-1
votes
0
answers
22
views
java.lang.RuntimeException: Could not setup GlassFish Embedded Bootstrap
I have a deployment class for integration tests in my project that is inheriterd by every test class. This class is annotated by:
@ArquillianSuiteDeployment
@RunWith(CustomArqullianRunner.class)
I'm ...
0
votes
0
answers
32
views
In Java, using Mockito fails to initialize MockMaker plugin
When I try to run this code:
package __6__240703.test.user_repository;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
import __6__240703.main.user_repository....
0
votes
1
answer
46
views
junit 5 runs specific cucumber feature twice
Running Cucumber with JUnit 5 works ok as long as all feature files are run.
@Suite
@IncludeEngines("cucumber")
@ConfigurationParameter(key = Constants.FEATURES_PROPERTY_NAME, value = "...
0
votes
0
answers
26
views
mockito, mock new file or mock file.exists() [duplicate]
Prerequisite: Powermockito cannot be used and the original code cannot be changed.
how to let
File file = new File("xxxx");
file.exists() returns true.
public void testFile(String path) {
...
0
votes
0
answers
23
views
How to pass a Junit Test for a Primefaces FileUploadEvent
i have a doubt about how to pass a JUnit test for a Primefaces FileUploadEvent.
The methods is this:
public void cambiarLogoCrear(FileUploadEvent event) {
cambiarLogo(event, false);
}
private ...