spring-boot-test

Spring boot test: Unable to instantiate inner configuration class

故事扮演 提交于 2019-12-11 15:29:31
问题 I want to run JUnit tests for my DAO layer without involving my main Spring configurations. As such, I declared an inner class annotated with @Configuration so that it would override the configurations of the main application class annotated with @SpringBootApplication . This is the code: @RunWith(SpringRunner.class) @JdbcTest public class InterviewInformationControllerTest { @Configuration class TestConfiguration{ @Bean public InterviewInformationDao getInterviewInformationDao(){ return new

@DataJpaTest how to specify repositories and entities to scan

江枫思渺然 提交于 2019-12-11 14:10:07
问题 By default @DataJpaTest scans all jpa repositories and @Entity . In my case I have 5 repositories package and 5 entities package. E.g com.acme.product.entity is associated with com.acme.product.repository com.acme.users.entity is associated with com.acme.users.repository com.acme.client.entity is associated with com.acme.client.repository And so on.... I would like to test each part in a separate classe. E.g. @RunWith(SpringRunner.class) @DataJpaTest //Some configurations to import only

How to use Kotlin beans dsl initializer in SpringBootTest

回眸只為那壹抹淺笑 提交于 2019-12-11 05:44:44
问题 I have a simple application with several beans declared with kotlin beans dsl: @SpringBootApplication class App val beans = beans { bean<A>() } fun main(args: Array<String>) { runApplication<MatchmakerApp>(*args) { addInitializers(beans) } } @RestController class AppController(val a: A) { // some code } class A and I have an integration test: @RunWith(SpringRunner::class) @SpringBootTest class AppControllerTest { @Test fun dummyTest() { assert(true) } } Launching this test I'm getting

Exception “At least one JPA metamodel must be present” thrown in Controller-Test

淺唱寂寞╮ 提交于 2019-12-11 05:33:06
问题 I am trying to test a controller class annotated with @RestController . I am using Spring-Boot 1.5.10 . The application itself starts up properly, but the unit test fails. Please bear in mind, that I am currently just trying to test the controller (and mock away the service - I will be testing the services later). Here are some of my classes: Application.java package com.particles.authservice; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure

How to test exception with @WebfluxTest

蹲街弑〆低调 提交于 2019-12-11 05:01:31
问题 I am trying to test exception path for my controller with @WebfluxTest , but it is always throws a server exception and then return a 500 error. The test codes is here: @Test @Ignore // ignore it temporarily public void getPostByNonExistedId_shouldReturn404() { given(posts.findById("1")) .willReturn(Mono.empty()); client.get().uri("/posts/1").exchange() .expectStatus().isNotFound(); verify(this.posts, times(1)).findById(anyString()); verifyNoMoreInteractions(this.posts); } The controller

Is there a way to run Karate tests as an integration test suite against a pre-booted spring boot server?

老子叫甜甜 提交于 2019-12-11 04:27:20
问题 Is there any good way to get Karate tests to test a Spring-Boot microservice in the "integration-test" phase of a Maven build? What I mean is: is there an anti-pattern/workaround that works well OR am I out of luck because this was an afterthought of the Karate development? Facts I have gathered so far: It says here: "the surefire plugin is not hardcoded into Karate" Is there a way to run Karate test during maven's integration test phase? Running Karate tests in context of maven-failsafe

Spring boot integration test fails with Neo4j

懵懂的女人 提交于 2019-12-08 19:54:30
I am new to spring boot. I use Spring Boot 1.5.1 GA and Neo4j starter of spring boot. I tried to create my very first integration test to whether I can insert a new object into the graph database. Here is my test class: package hu.bookandwalk; import static org.junit.Assert.assertEquals; import java.time.LocalDateTime; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.neo4j.ogm.testutil.TestServer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest

Matching object in JSON with jsonpath in Spring Boot Test

痞子三分冷 提交于 2019-12-08 08:56:20
问题 I'm trying to write unit tests for a rest endpoint with Spring Boot Test that's going well but when I try to assert on an object in the json response with jsonPath an AssertionError is thrown even when contents are identical and the same. Sample Json { "status": 200, "data": [ { "id": 1, "placed_by": 1, "weight": 0.1, "weight_metric": "KG", "sent_on": null, "delivered_on": null, "status": "PLACED", "from": "1 string, string, string, string", "to": "1 string, string, string, string", "current

Excluding Spring Integration from Spring Boot Test with Spring Boot 1.4

北城余情 提交于 2019-12-08 08:33:08
问题 I've recently began using Spring Boot 1.4 and the new Spring Boot Test feature. I'm using spring-boot-starter-integration with Spring Boot 1.4.2.RELEASE and attempting to test my repository with the new @DataJpaTest When I run my test I get an exception about no qualifying bean. The bean in question is the handler for my integration beans. How do I exclude integration from running during my JPA test? Application Class: import org.springframework.boot.SpringApplication; import org

How execute `schema.sql` during spring boot test without embeded datasource configuration?

烂漫一生 提交于 2019-12-08 05:04:38
问题 There is spring boot application with h2 database which is used as primary database. Also there is a resource/schema.sql wich is loaded at startup by spring boot. But during integration tests with @SpringBootTest spring boot does not load this schema.sql . Instead it requires to setup embeded database while there is h2 db already. Is there a way to execute schema.sql without embeded datasource configuration? And do it only once for all tests (e.g. using @Sql for schema creation for all test