Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SimpleClassTestListener extends AbstractTestExecutionListener {
- @Autowired
- protected String simplefield; // does not work simplefield = null
- @Override
- public void beforeTestClass(TestContext testContext) throws Exception {
- System.out.println("simplefield " + simplefield);
- }
- }
- @Configuration
- @ComponentScan(basePackages = { "com.example*" })
- class SimpleConfig {
- @Bean
- public String simpleField() {
- return "simpleField";
- }
- }
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(classes = { SimpleConfig.class })
- @TestExecutionListeners(mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS, listeners = {
- SimpleClassTestListener.class })
- public class SimpleTest {
- @Test
- public void test(){
- assertTrue();
- }
- }
- @Override
- public void beforeTestClass(TestContext testContext) throws Exception {
- testContext.getApplicationContext()
- .getAutowireCapableBeanFactory()
- .autowireBean(this);
- // your code that uses autowired fields
- }
- estContext.getApplicationContext()
- .getAutowireCapableBeanFactory()
- .autowireBean(this)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement