spring-test

Unable to find a SpringBootConfiguration in Spring Boot Test 1.4

被刻印的时光 ゝ 提交于 2020-01-02 04:40:11
问题 I'm not able to run a simple test in spring boot 1.4. I followed the tutorial from the official site testing-the-spring-mvc-slice but I didn't get it to work. every time i get the following error: java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test any ideas, hints? Thanks in advance Edit: this is the controller @Controller public class UserManagementController { @GetMapping(value = "

org.hibernate.service.UnknownServiceException: Unknown service requested

笑着哭i 提交于 2020-01-02 03:41:11
问题 I am writing a unit test to for my AbstractHibernateRepository save method. I'm using spring test runner but I get the following exception when it runs: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider] at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:201) My Test: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("file:src/main/webapp/WEB

Spring RestController + Junit Testing

纵饮孤独 提交于 2020-01-02 02:52:25
问题 I'm playing around with spring-test of springframework. My intention is to test the following POST method in my rest controller: @RestController @RequestMapping("/project") public class ProjectController { @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public Project createProject(@RequestBody Project project, HttpServletResponse response) { // TODO: create the object, store it in db... response.setStatus(HttpServletResponse.SC_CREATED); // return

Spring JUnit Test not loading full Application Context

拈花ヽ惹草 提交于 2020-01-02 01:21:16
问题 Hi I am trying to so spring junit test cases... and I require my full application context to be loaded. However the junit test does not initialize the full application context. Test class: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) public class MongoDbRepositoryTest { @Value("${spring.datasource.url}") private String databaseUrl; @Inject private ApplicationContext appContext; @Test public void testCRUD() { System.out.println("spring

Accessing spring context in testng's @BeforeTest

跟風遠走 提交于 2020-01-01 10:28:15
问题 I would like to register some web scopes to the spring context in my @BeforeTest method. But it turns out that spring context is still null at that point. The test runs fine though, if I change into @BeforeMethod . I wonder how I can access the context in @BeforeTest , because I don't want the scope registration code to be repeated for each test methods. Below are my code snippets. public class MyTest extends MyBaseTest { @Test public void someTest() { /*...*/ } } @ContextConfiguration

Use different Spring test context configuration for different test methods

♀尐吖头ヾ 提交于 2020-01-01 02:34:07
问题 We have a Spring based JUnit test class which is utilizing an inner test context configuration class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = ServiceTest.Config.class) public class ServiceTest { @Test public void someTest() { ... @Configuration @PropertySource(value = { "classpath:application.properties" }) @ComponentScan({ "..." }) public static class Config { ... New functionalities have been recently introduced to the Service class, for which the concerned

Spring test context best practice

雨燕双飞 提交于 2019-12-31 22:25:09
问题 I'm trying to cover a huge Spring Boot application with integration tests. There are lots of Spring beans within the app. It takes a while to load the Spring context. So I'm wondering - Is Spring clever enough to share the same context between multiple integration tests located in different classes? I mean to avoid initializing the heavy-weight context for each test class. What happens when tests 1,2,4 use TestContextOne and tests 3,5 use TestContextTwo ? Does Spring launch them in 1,2,4,3,5

Spring-Boot module based integration testing

℡╲_俬逩灬. 提交于 2019-12-30 08:52:05
问题 I have a multi-module Spring-Boot project. I was wondering how I can set up integration testing just to test Spring Data JPA repositories? The following approach fails with this exception: HV000183: Unable to load 'javax.el.ExpressionFactory'. Check that you have the EL dependencies on the classpath. Since this module does not depend on the web module, there is no web application that can be started. @RunWith(SpringJUnit4ClassRunner.class) @IntegrationTest @SpringApplicationConfiguration

How to call Springs service method from controller (Junit)

此生再无相见时 提交于 2019-12-25 15:59:31
问题 I have seen example , how to call spring controller using mockito. Using Mock I call Spring MVC controller. Controller Invokes Spring service class. @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/root-context.xml" }) public class TestController { @Mock private TestService testService; @InjectMocks private PaymentTransactionController paymentController; private MockMvc mockMvc; @Before public void setup() {

SpringBoot TestRestTemplate and LocalDateTime not working

六眼飞鱼酱① 提交于 2019-12-25 03:12:25
问题 I am using LocalDateTime in my model, after including LocalDateTimeDeserializer, converted the bean field to @NotNull @Column(name = "created") @JsonDeserialize(using = LocalDateTimeDeserializer.class) private LocalDateTime created; and included the spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false property in the SpringBoot's application.properties file, the application is finally able to deserialize the JSON and show properly like, "created": "2018-04-22T21:21:53.025", But,