Skip to content
Permalink
Browse files

How to add additional spring test configuration

  • Loading branch information...
slem1 committed Oct 19, 2017
1 parent ffd8316 commit 0ec6c0559e448f2bc4c22c5615527475f259d44e
@@ -7,4 +7,6 @@
*/
@Component
public class MyComponent {

public void print(){}
}
@@ -1,6 +1,8 @@
package fr.sle.testhowto.test;

import fr.sle.testhowto.MyComponent;
import fr.sle.testhowto.test.config.AdditionalTestConfig;
import fr.sle.testhowto.test.config.AdditionnalTestComponent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -11,14 +13,17 @@
* @author slemoine
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = AdditionalTestConfig.class)
public class MyComponentTestClass {

@Autowired
private MyComponent component;

@Test
public void myComponentTestMethod(){
@Autowired
private AdditionnalTestComponent additionnalTestComponent;

@Test
public void myComponentTestMethod() {
component.print();
}
}
@@ -0,0 +1,27 @@
package fr.sle.testhowto.test.config;

import fr.sle.testhowto.MyComponent;
import org.mockito.Mockito;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;

/**
* @author slemoine
*/
@TestConfiguration
public class AdditionalTestConfig {

@Bean
public AdditionnalTestComponent additionnalTestComponent() {
return new AdditionnalTestComponent();
}

/**
* A Mock if {@link MyComponent} class
* @return the mock
*/
@Bean
public MyComponent component() {
return Mockito.mock(MyComponent.class);
}
}
@@ -0,0 +1,7 @@
package fr.sle.testhowto.test.config;

/**
* Additional component class for test
*/
public class AdditionnalTestComponent {
}

0 comments on commit 0ec6c05

Please sign in to comment.
You can’t perform that action at this time.