Skip to content
Advertisement

Tag: junit

How can I unit-test Exception thrown inside a Lambda?

I have a method: This is how the user authorization test looks like: Is there any way to check the case when a user has entered the wrong password? In the case when I send the wrong password, it doesn’t work because given(this.repository.findByEmail(this.user.getEmail())).willReturn(Optional.of(this.user)); makes repository.findByEmail() return the result before you get to checking the password. Answer You don’t need this

Mocking Instance with deep stubs

I want to mock a lazy injection with deep stubs using: But myClassInstance.get().myMethod() results in a NullPointerException because myClassInstance.get() returns null instead of a mock. Is this an unsupported feature or am I doing something wrong? I’m using junit-jupiter 5.9.0 and mockito-junit-jupiter 4.6.1. Answer This is a result of erasure of generic types. Mockito does not have access to the

How to run mock server tests in isolation?

I have these two mock server tests. When I launch these, the second test fail because the two tests are not launched in isolation. The mocking of the HTTP call in the first method isn’t override in the second method. Is there a Mock Server property or a JUnit property to run these two tests in isolation ? Answer At

Use H2 as test DB in JUnit5

I’m developing an app in Spring Boot. I use a PostreSQL DB for production, and I want my JUnit 5 tests to run on a H2 memory DB. Problem is, after some configuration, the tests still don’t seem to run on the in-memory db: I can access entities from the prod db (a saved entity doesn’t persist in the prod

assertAll a list of booleans

There is a list of pages that can be accessed by a user. The verifyAccess has a function that returns true/false depending on which page the user is trying to access. For example – look for the profile IMG locator on a profile page, the Logout button on the logout page, and so on … I am using below imports

Karate: runners class with JUnit5

sorry for the naive question: What are the references to “sample” and “tags” in the example documentation that explains the configuration of tests with Junit5? Are these features? Thanks Answer Yes, it tries to be more concise instead of sample.feature etc. Refer the docs: https://github.com/karatelabs/karate#junit-5

Should such a class be tested? (aggregation of already tested functions)

I have the following code in Class A where both requestService.createGetSessionRequest() and httpService.sendAsyncAndReceive() are tested already in other unit tests: I am wondering, should I even create tests for A.createSession()? Basically it seems that it could be useful as a developer might accidentally mix up the parameters when calling requestService.createGetSessionRequest() in A.createSession()’s implementation as they’re all strings. On the other

Mockito is returning the incorrect response when testing a controller

I Have a misterius. Im trying to write a Test for this controller Method: And I DID this: I don’t know why but the method ResponseEntity<Object> response = controller.getIncidencia(ID); is returning <404 NOT_Found Not Found, Incidencia Not Found []> But the corret would be 200 OK. What I did Wrong? Answer I discovered but I do know why. I re-wrote

Advertisement