spring junit 部署两套测试方案

第一套方案:

1、初始化application:使用@ContextConfigurationr的classpath属性,如

@ContextConfiguration(locations =
{ "/META-INF/spring/applicationContext-mutiDs.xml", "/META-INF/spring/applicationContext-timer.xml" })

@RunWith(SpringJUnit4ClassRunner.class)

@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class})

@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)

@Transactional

public class A

或者

在@Before

public void prepareInit() {

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath*:META-INF/spring/*.xml");

context.start();

}

第二套方案:

1、使用自己的application.xml和自己的数据

@ContextConfiguration(locations = {"file:src/test/resources/applicationContext.xml",
"file:src/test/resources/dubbo-mdb-provider.xml"})

2、然后把相关的数据库配置放在test目录下面。

3、搞定,两套方案完成。

 

posted @   ppjj  阅读(232)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示