项目结构如图,是基于Maven的多模块,想在DAO模块单独进行单元测试,但总是出BUG,无法创建EntityManager。求大佬们教教怎么搞这个!
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean named 'entityManagerFactory' that could not be found.
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
测试的注解如下:
@ComponentScan("com.xxx.configuration")
@EnableJpaRepositories(basePackages="com.xxx.users.repository")
@EntityScan("com.xxx.domain")
@SpringBootConfiguration
@EnableConfigurationProperties(JpaProperties.class)
public class XXXDaoApplication {
public static void main(String[] args) {
SpringApplication.run(XXXDaoApplication.class, args);
}
}
@RunWith(SpringRunner.class)//JUnit4的测试
@SpringBootTest(classes = XXXDaoApplication.class)
public class XXXDaoApplicationTests {
@Inject
XXXRepository repository;
@Test
public void test() throws Exception {
.....
}
}
另外,欢迎加入软件测试技术交流群 313782132 ~进群可领取软件测试资料以及群内测试大牛解惑!
测试工程师职业发展路线图 功能测试 —— 接口测试 —— 自动化测试 —— 测试开发 —— 测试架构师 加油吧,测试人!如果你需要提升规划,那就行动吧,在路上总比在起点观望的要好。事必有法,然后有成。 资源不错就给个推荐吧~