问题描述
我使用以下简单代码跟踪spring integration testing doc:
ListenerTest.java ,入口
b
package learn.spring.test;
import learn.spring.model.Person;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = SimpleConfig.class)
// @TestExecutionListeners(MyTestExecutionListener.class)
public class ListenerTest {
@Autowired
Person person;
@Test
public void basic() {
assertNotNull(person);
}
}
package learn.spring.test;
import learn.spring.model.Person;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SimpleConfig {
@Bean
public Person rick() {
return new Person("Rick");
}
}
package learn.spring.test;
import lombok.extern.slf4j.Slf4j;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestExecutionListener;
@Slf4j
public class MyTestExecutionListener implements TestExecutionListener {
@Override
public void beforeTestExecution(TestContext testContext) throws Exception {
log.info("before {}",testContext.getTestMethod());
}
}
是一个简单的简单POJO,应该安全地省略。
在评论Person
的情况下,测试将通过。但是,@TestExecutionListeners
如果未注释,将失败。
assertNotNull(person);
似乎以某种方式禁用了自动接线。我在做什么错了?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)