As the title says I accidentally deleted my test folder in Spring boot application and created a folder named test under src folder. But now I can’t create java class in test folder.IDE does not recognize it as a java class. What can I do to fix this? Answer Create the java in the test directory. If you use IDEA,
Tag: testing
Why my test passes without a bearer token
I have a simple Spring app. But I don’t understand why the test passes without the need of a bearer token. Here is the controller: Security Configuration: In order to setup the security configs for tests I’m using: So my test class looks like this: If I change the autority in the test to something like ‘foo-user’ the response becomes
Validation failed for query in tests but not in production
Problem description I have the following test class with a few tests. The setUp() method executes insert statements from a file. The first test simply makes a post request and expects an array of JSON objects in return with a 200(OK) status: Upon running the first test I get the following error: What I Tried Spring obviously does not like
Use a secondary h2 database for testing an API in Spring boot
I’m developing an API to manage a database in the company where I work, the problem is that when I have to run the different test I have to use the “real” dev database (in h2) where I have some real data. I thought about it and what I wanted to do is create a new h2 database that could
How to mock my service using Mockito framework
Hello I have struglling write a mock test according to my following method below; my code below; my yml configuration below; my service below; I have a created PropertySourceResolver class and my test class below; I like to change my code according to test scenarios like ; when … then return any idea? thank you. Answer To make this simpler
How to make an integration test with one transaction for all database calls and rollback it afterwards?
I’m, writing an integration test, annotated with @SpringBootTest. Suppose I create some product using pure SQL from my test, call calculation service that do some calculations based on it, and it calls another service to save those calculation results in different tables. What I need is to rollback all the changes made after test is finished. I read different questions,
Mockito – verify a method call with expected argument but ignore certain fields
I am mocking a class called EmailSender which has a method sendEmail() that takes in an argument of class Email. I am trying to verify that my mockEmailSender will call the sendEmail function once with the expected Email class as such: verify(mockEmailSender, times(1)).sendEmail(expectedEmail) I am initializing the expected Email object like the follow Email expectedEmail = Email.builder().setRecipients(//example list).setTitle(“Test title”).setBody(//make this
How to test Service method with ModelMapper call
I’m writing some Unit Tests for my Service class, specifically, an update method that does exactly that, update an Entity with the given data from a request. The problem is, I’m using ModelMapper to map the request data to the entity and when the test goes through the mapping statement it doesn’t actually call the modelMapper but the mock ….
How to load json data in java?
I’m quite new to API testing, I am wondering how to best and simple load some body? I created simple pojo classes, but i am having problems with nested json. ex: Then, in classes I used: and then in test class I am trying to use it, but have no idea how. But I have no idea how to declare
how to stub a method in a class which is called from another class
I’m not able to get my method to return the desired value. Above implementations shows how I have written my test, but it’s not working. What am i doing wrong here? Answer Yet to clarify given answers: your mistake is that you do not actually use that spy/mock anywhere. In your class A you have a static method where a