Questions tagged [spring-boot-test]

Spring Boot provides utilities and annotations to help when testing your application.

Spring Boot provides a @SpringBootTest annotation which can be used as an alternative to the standard spring-test @ContextConfiguration annotation when you need Spring Boot features. The annotation works by creating the ApplicationContext used in your tests via SpringApplication.

Utilities: ConfigFileApplicationContextInitializer,EnvironmentTestUtils,OutputCapture and TestRestTemplate

for example

EnvironmentTestUtils.addEnvironment(env, "org=Spring", "name=Boot");

Docs: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html

1399 questions
0
votes
0 answers

ClassNotFoundException: org.junit.Assert exception when using MockRestServiceServer

I'm trying to run the following test import org.springframework.test.web.client.MockRestServiceServer; .... @Test void successPost () { MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build(); …
Omar
  • 101
  • 2
0
votes
1 answer

Is it possible to use an ErrorController with a @WebMvcTest?

I have an error controller (to handle the path "/error") that works when the application is running, but when in an unit test with @WebMvcTest it does not work. The error controller also works if I send a request direct to its path. This is my error…
0
votes
1 answer

Spring Boot @Converter always accessible with @SpringBootTest

I have a Spring Boot application which uses the following converter. @Converter(autoApply = true) class LocalDatePersistenceConverter implements AttributeConverter { @Override public java.sql.Date…
0
votes
0 answers

unit testing a java method by calling the method in multiple threads

I have a spring bootproject with several services. Im writing junit test for a method that defines a service that reads value from database and updates it with the new value in the database. I want to do unit testing for the method by calling it in…
Rohan RM
  • 157
  • 1
  • 2
  • 10
0
votes
1 answer

org.junit.ComparisonFailure: expected: but was:

I am running Junit test case for service layer but I am getting org.junit.ComparisonFailure: expected:VendorEntity@3e60be48 but was:null When vendorRepo.save(vendorEntity) method is called it returns null, I am not able to figure out why it is…
pise
  • 849
  • 6
  • 24
  • 51
0
votes
1 answer

Failed to update using DataJpaTest spring boot 2.1.0

Using unit test for a spring boot parent 2.1.0. I need to test the update of values after applying update to a List object inside Game object. I read in another thread to add the following statement but could't use in my case …
Nesrin
  • 395
  • 3
  • 8
0
votes
1 answer

SprintBootTest - create only necessary beans

I have a code similar to the follows: @RunWith(SpringRunner.class) @SpringBootTest public class ModelRunnerTest { @Autowired private SomeRepository repository; @Autowired private SomeSearcher someSearcher; @Test public…
user1028741
  • 2,745
  • 6
  • 34
  • 68
0
votes
1 answer

Spring Boot MVC Test 404 with Valid Request

I am using Spring Boot 2.0.6 and have set up a test for a controller: the method is as follows: @Secured("ROLE_ADMIN") @GetMapping(value = {"/maintainers/aircrafts/workorders/workitems/{wid}/parts"}, produces =…
0
votes
0 answers

MockMvc PostRequest Exception

I have following post mapping. @PostMapping(value = BULK_UPDATE) @ApiOperation(value = "Bulk Update of Markets by pairs of Market Key and Tier Quantity Id", tags = "Bulk", code = 200) @ApiImplicitParams({ @ApiImplicitParam(name =…
Nilamber Singh
  • 804
  • 1
  • 14
  • 33
0
votes
2 answers

EmbeddedKafka AdminClient shuts down before Spring app starts for tests

I'm trying to write integration tests for a Spring Kafka app (Spring Boot 2.0.6, Spring Kafka 2.1.10) and am seeing lots of instance of INFO org.apache.zookeeper.server.PrepRequestProcessor - Got user-level KeeperException when processing…
0
votes
1 answer

SpringBoot test configuration

I've started to learn Spring Boot in version 2.1.0 and I made a simple application Controller->Service->Repository->Database(H2). Very, very simple application just to start with Spring Boot. I've read that in that framework I can add under…
Kacu
  • 438
  • 4
  • 23
0
votes
1 answer

Same instances between tests

I wrote two test(I mean different classes) that is configured with this annotations: @RunWith(SpringRunner.class) @SpringBootTest When I run them solitary - everything is Ok Magic happens when I run them simultaneously using 'test' task from gradle.…
0
votes
1 answer

SpringBootTest: Getting java.lang.NullPointerException when calling CRUD repository in @component test file

I am a beginner in testing and now I have a problem that I cannot overcome. @SpringBootTest ExampleMakerSpec extends Specification { @Autowired @Subject ExampleMaker exampleMaker @Autowired ExampleRepository exampleRepository def EXAMPLE_VARIABLE…
Jamel
  • 33
  • 1
  • 4
0
votes
1 answer

springboot controller test does not handle exception

I am new to SpringBoot and it has been some time since working with SpringMVC,so likely I am missing something obvious. My test calls the controller and the controller throws an IllegalArgumentException just as I intend. However, the test does not…
Bill Turner
  • 869
  • 1
  • 13
  • 27
0
votes
1 answer

Spring Boot 2: IntegrationTest should not execute CommandLineRunner impl

i don't get it: The Application code is executed during my integration tests. Here is my Application class: @SpringBootApplication public class Application implements CommandLineRunner { public static void main(String[] args) { …
user5012221
  • 13
  • 1
  • 4