Mockito注解解析以及控制台打印

注解以及作用:
压制警告
@SuppressWarnings("deprecation")
表示使用Spring Test组件进行单元测试;
@RunWith(SpringJUnit4ClassRunner.class)
保证每次测试类执行完后数据库进行回滚,防止测试时产生脏数据
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true )
@Transactional  
指定Bean的配置文件信息,可以有多种方式,这个例子使用的是文件路径形式,如果有多个配置文件,可以将括号中的信息配置为一个字符串数组来表示;
如果spring的配置文件在默认的目录下
@ContextConfiguration(locations = "classpath:spring-config.xml")
如果spring的配置文件放在WEB-INF目录下,需要使用这种方法
@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring-config.xml"})
指定使用哪一个配置文件:dev int uat pro
@ActiveProfiles("dev")  
@SpringApplicationConfiguration(classes=ServiceApplication.class)
使用这个Annotate会在跑单元测试的时候真实的启一个web服务,然后开始调用Controller的Rest API, 待单元测试跑完之后再将web服务停掉;
@WebAppConfiguration

我结合控制台打印信息查看后发现,这里的配置信息其实都能打印出来的,如下面:
下图是我自行翻译的,其实是汉式翻译,有大神看到希望可以指导下!
2017-3-21 09:41:22 main INFO Began transaction (1) for test context
[
DefaultTestContext@8cd36b                                                    默认测试内容@: 
testClass = PersonControllerTest,                                            测试类: PersonControllerTest
testInstance = com.smile.userinfo.success.PersonControllerTest@18d9199,      测试实例:PersonControllerTest@18d9199@
testMethod = updatePersonInfoTest@PersonControllerTest,                      测试方法: updatePersonInfoTest@PersonControllerTest
testException = [null],                                                      测试异常:null 
mergedContextConfiguration =                                                 配置上下文信息:  
[                    
WebMergedContextConfiguration@1fa56fa                                        配置上下文信息实例@
testClass = PersonControllerTest,                                            测试类: PersonControllerTest
locations = '{}',                                                            位置信息: 
classes = '{class com.smile.ServiceApplication}',                            启动类:ServiceApplication
contextInitializerClasses = '[]',                                            上下文初始化程序: 
activeProfiles = '{}',                                                       活动的配置文件: 
propertySourceLocations = '{}',                                              本地资源属性: 
propertySourceProperties = '{}',                                             配置文件资源属性: 
contextCustomizers = set                                                     上下文定制器:
[                         
org.springframework.test.context.web.socket.MockServerContainerContextCustomizer@12cdcf4,  Mock  org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@169c6ba,       过滤器:执行上下问配置过滤器   org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0                       mock配置器
],
resourceBasePath = 'src/main/webapp',                                        基本资源地址:src/main/webapp  
contextLoader = 'org.springframework.boot.test.SpringApplicationContextLoader',   上下文加载器
parent = [null]                                                               父节点:null
]
];


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值