- 浏览: 959247 次
- 性别:
- 来自: 江西上饶
文章分类
- 全部博客 (460)
- p.spring (56)
- p.maven (20)
- p.ant (17)
- p.jee (18)
- p.jse (33)
- p.ofbiz (31)
- p.软件工程 (8)
- p.struts2 (5)
- p.hibernate (5)
- linux (25)
- 设计模式 (2)
- p.javascript (11)
- 硬件 (1)
- p.jsp (2)
- p.windows批处理 (1)
- 操作系统问题 (5)
- 算法 (1)
- p.mysql (7)
- p.sql (5)
- p.c (1)
- google产品 (0)
- 内存 (1)
- p.struts (1)
- p.freemarker (7)
- p.css (4)
- p.log4j (10)
- p.html (3)
- 淘宝产品 (0)
- 其他 (3)
- 编译器 (0)
- svn (4)
- p.spring.security (11)
- 图形 (0)
- p.xml (1)
- p.ssh (0)
- p.jquery (4)
- p.jdbc (3)
- p.flex (0)
- p.c++ (0)
- p.c#Net (0)
- p.assembly (0)
- p.sqlserver (0)
- p.其他 (3)
- p.webwork (21)
- p.wap (12)
- p.cglib (1)
- p.jee服务器 (11)
- windows (2)
- p.iphone (1)
- p.java.分布式与集群 (2)
- p.ibatis (16)
- p.eclipse (5)
- 架构 (2)
- http协议 (5)
- 我的个人标准 (2)
- 多线程 (1)
- 奇怪问题 (5)
- p.jira (13)
- p.httpclient (1)
- 服务器.apache (11)
- 安全防范 (1)
- p.PODAM (1)
- p.junit (16)
- fop (2)
- 硬盘安装 (1)
- powerdesigner (0)
- 单元测试 (1)
- apache commons (4)
- tomcat+apache集群 (10)
- 各类诡辩 (1)
- 安卓 (8)
- qvod (1)
- java编程基础知识考试考点及答案 (0)
- 工作总结 (4)
- oracle (0)
- spring的util工具 (3)
- json (2)
- maven (3)
- jms (19)
- p.bat (3)
- hadoop (2)
- git (3)
- nginx (1)
- p.移动开发 (1)
- shiro (3)
- 游戏破解 (1)
- react-native (7)
- ios开发 (1)
- webmagic (6)
- socks5 (1)
最新评论
-
weituotian:
说的不好,没人看的
公司系统中的菜单功能和权限功能 -
石不易:
非常详细的注解~
绑定端口和IP,Listen 与VirtualHost指令 -
spring_springmvc:
spring mvc demo教程源代码下载,地址:http: ...
spring mvc -
liyixing1:
PandaDONG 写道谢谢你啊,我已经下下来了,只是还有很多 ...
jira war安装 -
liyixing1:
PandaDONG 写道谢谢你啊,我已经下下来了,只是还有很多 ...
jira war安装
spring提供了各种mock工具
JNDI
org.springframework.mock.jndi包下面
Servlet API
org.springframework.mock.web包下面。
Portlet API
org.springframework.mock.web.portlet包下面
公用测试帮助类
org.springframework.test.util,用于给一些特殊的变量,如hibernate的configuration配置属性(他们的属性都是私有的)。如类ReflectionTestUtils。
springmvc
org.springframework.test.web包得ModelAndViewAssert
测试springmvc需要用到
ModelAndViewAssert
MockHttpServletRequest
MockHttpSession
org.springframework.mock.web下面的其他类
package com.superschool.test;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.web.ModelAndViewAssert;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
import com.superschool.action.MyAction;
import com.superschool.service.IMy;
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:/com/superschool/resource/spring/context/application/applicationContext.xml",
"classpath:/com/superschool/resource/spring/context/web/superschool-servlet.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
@Transactional
public class TestMy {
@Autowired
private IMy test;
@Autowired
private MyAction action;
@Resource(type = AnnotationMethodHandlerAdapter.class)
private HandlerAdapter handlerAdapter;
@BeforeTransaction
public void beforeTransaction() {
System.out.println("事物开始了");
}
@Test
@Rollback(false)
public void testMy() {
Assert.assertTrue(test.add());
}
@Test
public void testMyAction() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("get", "/");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mv = handlerAdapter.handle(request, response, action);
ModelAndViewAssert.assertViewName(mv, "index");
}
}
集成测试
这个时候我们更多的希望不是将测试部署到服务器或者实际环境中。
如SPRING的ioc。
orm中间件。
1.上下文
spring提供的上下文对象ApplicationContext的mock。
ApplicationContext只会mock一次。
2.对于事物管理
我们可能会对测试数据进行修改操作,而修改操作可能会造成下一次的测试失败。而SPRING则提供了完美的事物管理,可以在我们结束测试后,恢复数据。
3.集成测试
spring提供了几个方便的类来书写集成测试。
4.jdbc测试
org.springframework.test.jdbc.SimpleJdbcTestUtils是对jdbc的支持。
提供的注解
@ContextConfiguration
定义类级别的注解,用于设置如何加载mock applicationcontext。
package com.superschool.test.demo;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.support.GenericXmlContextLoader;
@ContextConfiguration(locations = { "classpath:com/superschool/resource/spring/context/application/applicationContext.xml" }, loader = GenericXmlContextLoader.class)
public class TestA {
@Test
public void testMy() {
Assert.assertTrue(true);
}
}
@DirtiesContext
表示测试完成后会破坏applicationContext。需要重新加载applicationContext。
mode属性可以设置为AFTER_CLASS表示当前类结束后,applicationContext需要重新mock。
AFTER_EACH_TEST_METHOD每个测试方法结束后都需要重新mock。
如果生命在一个方法上面,那么表示当前方法结束后,需要重新mock。
package com.superschool.test.demo;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.support.GenericXmlContextLoader;
@ContextConfiguration(locations = { "classpath:com/superschool/resource/spring/context/application/applicationContext.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
public class TestA {
@DirtiesContext
@Test
public void testMy() {
Assert.assertTrue(true);
}
}
@TestExecutionListeners
定义类级别的元数据配置。改注解应该同时配置一个TestContextManager。一般和ContextConfiguration注解同时使用,ContextConfiguration mock出来的TestContxt就是TestContextManager。
package com.superschool.test.demo;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
@ContextConfiguration(locations = { "classpath:com/superschool/resource/spring/context/application/applicationContext.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TestExecutionListeners({ TransactionalTestExecutionListener.class })
public class TestA {
@DirtiesContext
@Test
public void testMy() {
Assert.assertTrue(true);
}
}
@TransactionConfiguration
事物配置
transactionManager属性设置一个bean name,用来获取
PlatformTransactionManager 类型的bean。默认值是transactionManager。这个值应和tx:annotation-driven mode="proxy"
transaction-manager="transactionManager" />这里的相同。
defaultRollback 默认回滚属性。true表示测试结束恢复数据。
通常和ContextConfiguration同时存在。
package com.superschool.test.demo;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
@ContextConfiguration(locations = { "classpath:com/superschool/resource/spring/context/application/applicationContext.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TestExecutionListeners({ TransactionalTestExecutionListener.class })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@DirtiesContext
@Test
@Rollback(false)
public void testMy() {
Assert.assertTrue(true);
}
}
@BeforeTransaction表示在事物开始前运行,需要@Transactional注解才能有效
package com.superschool.test.demo;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
@ContextConfiguration(locations = { "classpath:com/superschool/resource/spring/context/application/applicationContext.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TestExecutionListeners({ TransactionalTestExecutionListener.class })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@BeforeTransaction
public void beforeTransaction() {
System.out.println("事物开始了");
}
@DirtiesContext
@Test
@Rollback(false)
public void testMy() {
Assert.assertTrue(true);
}
}
@AfterTransaction
类似
@NotTransactional
表示这个方法必须运行在一个非事物上下文下面。已经过时。
@Rollback
测试结束后是否回滚
配置在方法上面。
package com.superschool.test.demo;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
@ContextConfiguration(locations = { "classpath:com/superschool/resource/spring/context/application/applicationContext.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TestExecutionListeners({ TransactionalTestExecutionListener.class })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@DirtiesContext
@Test
@Rollback(false)
public void testMy() {
Assert.assertTrue(true);
}
}
一个例子
package com.superschool.test.demo;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import com.superschool.service.TestI;
@RunWith(value = SpringJUnit4ClassRunner.class)
//注意主力的classpath:后面以/开头,因为不以/开通,spring就会相对当前测试类所在的包往下递归找
@ContextConfiguration(locations = {
"classpath:/com/superschool/resource/spring/context/application/applicationContext.xml",
"classpath:/com/superschool/resource/spring/context/web/superschool-servlet.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@Resource
private TestI test;
@BeforeTransaction
public void beforeTransaction() {
System.out.println("事物开始了");
}
@DirtiesContext
@Test
@Rollback(false)
public void testMy() {
test.test();
Assert.assertTrue(true);
}
}
@IfProfileValue
当某个属性(properties形式的)存在或者给它指定一个值,只有值为这个值的时候才会执行这个测试。
package com.superschool.test.demo;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import com.superschool.service.TestI;
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:/com/superschool/resource/spring/context/application/applicationContext.xml",
"classpath:/com/superschool/resource/spring/context/web/superschool-servlet.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@Resource
private TestI test;
@BeforeTransaction
public void beforeTransaction() {
System.out.println("事物开始了");
}
@DirtiesContext
@Test
@Rollback(false)
@IfProfileValue(name = "java.vendor")
public void testMy() {
Assert.assertTrue(test.test());
}
@DirtiesContext
@Test
@Rollback(false)
@IfProfileValue(name = "java.vendor", value = "xxxxxx")
public void testMy1() {
Assert.assertTrue(test.test());
}
}
上面的例子定义了两个例子,一个只要定义了java.vendor属性就会执行。
一个是只有当属性java.vendor值等于xxxxxx才会执行。
也可以以组的方式存在
@IfProfileValue(name="test-groups", values={"unit-tests", "integration-tests"})
@Test
public void testProcessWhichRunsForUnitOrIntegrationTestGroups() {
// some logic that should run only for unit and integration test groups
}
只有有一个满足就可以了。
@ProfileValueSourceConfiguration
类级别的注解,指定IfProfileValue读取属性的实现类。默认是SystemProfileValueSource
@ExpectedException
预期测试将会抛出的异常。如果异常没有抛出或者类型不一样,将会测试失败。
@ExpectedException(SomeBusinessException.class)
public void testProcessRainyDayScenario() {
// some logic that should result in an Exception being thrown
}
@Timed
预期执行最大的时间。
spring的@Timed和junit的Timeout 区别是spring超时也不会立即停止,而是等待测试结束,计算总时间。包括重复的时间。
@Repeat
表示改测试将会重复执行N次
package com.superschool.test.demo;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import com.superschool.service.TestI;
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:/com/superschool/resource/spring/context/application/applicationContext.xml",
"classpath:/com/superschool/resource/spring/context/web/superschool-servlet.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@Resource
private TestI test;
@BeforeTransaction
public void beforeTransaction() {
System.out.println("事物开始了");
}
@Repeat(10)
@DirtiesContext
@Test
@Rollback(false)
public void testMy() {
Assert.assertTrue(test.test());
}
}
另外还支持spring的其他所有注解。
@Autowired
• @Qualifier
• @Resource (javax.annotation) if JSR-250 is present
• @Inject (javax.inject) if JSR-330 is present
• @Named (javax.inject) if JSR-330 is present
• @Provider (javax.inject) if JSR-330 is present
• @PersistenceContext (javax.persistence) if JPA is present
• @PersistenceUnit (javax.persistence) if JPA is present
• @Required
• @Transactional
TestContextManager是测试的入口。
TestExecutionListener定义了监视时间的API
上下文的管理一般不会去理会,但是有时候需要访问的话
可以
package com.superschool.test.demo;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import com.superschool.service.TestI;
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:/com/superschool/resource/spring/context/application/applicationContext.xml",
"classpath:/com/superschool/resource/spring/context/web/superschool-servlet.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@Resource
private TestI test;
@Autowired
private ApplicationContext applicationContext;
@BeforeTransaction
public void beforeTransaction() {
System.out.println("事物开始了");
}
@Repeat(10)
@DirtiesContext
@Test
@Rollback(false)
public void testMy() {
Assert.assertTrue(test.test());
}
}
@ContextConfiguration(locations = {
"classpath:/com/superschool/resource/spring/context/application/applicationContext.xml",
"classpath:/com/superschool/resource/spring/context/web/superschool-servlet.xml" }, loader = GenericXmlContextLoader.class)
这里的loader=GenericXmlContextLoader.class可以不需要,因为它就是默认加载器。
默认情况下会加载当前包下面的MyTest-context.xml
如你的测试类是com.example.MyTest
那么会加载classpath:/com/example/MyTest-context.xml
另外如果要自己写classpath应该是classpath:/xx/xxxx/xxxx而不是classpath:xx/xxxx/xxxx
。因为如果写classpath:/xx/xxxx/xxxx它会在当前包下面查找xx.xxxx子包的xxxx文件
正常情况下ApplicationContext只加载一次,这个测试类之后的测试都重用一个applicationcontext。
inheritLocations属性 表示从父类加载。
默认是true
@RunWith(SpringJUnit4ClassRunner.class)
// ApplicationContext will be loaded from "/base-context.xml" in the root of the classpath
@ContextConfiguration("/base-context.xml")
public class BaseTest {
// class body...
}
// ApplicationContext will be loaded from "/base-context.xml" and "/extended-context.xml"
// in the root of the classpath
@ContextConfiguration("/extended-context.xml")
public class ExtendedTest extends BaseTest {
// class body...
}
默认情况下会自动配置一个DependencyInjectionTestExecutionListener的TestExecutionListeners。它会自动注入属性。
如
@RunWith(SpringJUnit4ClassRunner.class)
// specifies the Spring configuration to load for this test fixture
@ContextConfiguration("daos.xml")
public final class HibernateTitleDaoTests {
// this instance will be dependency injected by type
@Autowired
private HibernateTitleDao titleDao;
public void testLoadTitle() throws Exception {
Title title = this.titleDao.loadTitle(new Long(10));
assertNotNull(title);
}
}
@RunWith(SpringJUnit4ClassRunner.class)
// specifies the Spring configuration to load for this test fixture
@ContextConfiguration("daos.xml")
public final class HibernateTitleDaoTests {
// this instance will be dependency injected by type
private HibernateTitleDao titleDao;
@Autowired
public void setTitleDao(HibernateTitleDao titleDao) {
this.titleDao = titleDao;
}
public void testLoadTitle() throws Exception {
Title title = this.titleDao.loadTitle(new Long(10));
assertNotNull(title);
}
}
这种方式完全符合spring的注入规则。包括Resource注解。Qualifier注解
默认情况下会自动配置一个TransactionalTestExecutionListener。但是你必须设置的PlatformTransactionManager bean
如
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
另外还要加入
@Transactional
测试支持类
org.springframework.test.context.junit4包
运行器
@RunWith(SpringJUnit4ClassRunner.class)
会自动加载配置
JNDI
org.springframework.mock.jndi包下面
Servlet API
org.springframework.mock.web包下面。
Portlet API
org.springframework.mock.web.portlet包下面
公用测试帮助类
org.springframework.test.util,用于给一些特殊的变量,如hibernate的configuration配置属性(他们的属性都是私有的)。如类ReflectionTestUtils。
springmvc
org.springframework.test.web包得ModelAndViewAssert
测试springmvc需要用到
ModelAndViewAssert
MockHttpServletRequest
MockHttpSession
org.springframework.mock.web下面的其他类
package com.superschool.test;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.web.ModelAndViewAssert;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
import com.superschool.action.MyAction;
import com.superschool.service.IMy;
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:/com/superschool/resource/spring/context/application/applicationContext.xml",
"classpath:/com/superschool/resource/spring/context/web/superschool-servlet.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
@Transactional
public class TestMy {
@Autowired
private IMy test;
@Autowired
private MyAction action;
@Resource(type = AnnotationMethodHandlerAdapter.class)
private HandlerAdapter handlerAdapter;
@BeforeTransaction
public void beforeTransaction() {
System.out.println("事物开始了");
}
@Test
@Rollback(false)
public void testMy() {
Assert.assertTrue(test.add());
}
@Test
public void testMyAction() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("get", "/");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mv = handlerAdapter.handle(request, response, action);
ModelAndViewAssert.assertViewName(mv, "index");
}
}
集成测试
这个时候我们更多的希望不是将测试部署到服务器或者实际环境中。
如SPRING的ioc。
orm中间件。
1.上下文
spring提供的上下文对象ApplicationContext的mock。
ApplicationContext只会mock一次。
2.对于事物管理
我们可能会对测试数据进行修改操作,而修改操作可能会造成下一次的测试失败。而SPRING则提供了完美的事物管理,可以在我们结束测试后,恢复数据。
3.集成测试
spring提供了几个方便的类来书写集成测试。
4.jdbc测试
org.springframework.test.jdbc.SimpleJdbcTestUtils是对jdbc的支持。
提供的注解
@ContextConfiguration
定义类级别的注解,用于设置如何加载mock applicationcontext。
package com.superschool.test.demo;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.support.GenericXmlContextLoader;
@ContextConfiguration(locations = { "classpath:com/superschool/resource/spring/context/application/applicationContext.xml" }, loader = GenericXmlContextLoader.class)
public class TestA {
@Test
public void testMy() {
Assert.assertTrue(true);
}
}
@DirtiesContext
表示测试完成后会破坏applicationContext。需要重新加载applicationContext。
mode属性可以设置为AFTER_CLASS表示当前类结束后,applicationContext需要重新mock。
AFTER_EACH_TEST_METHOD每个测试方法结束后都需要重新mock。
如果生命在一个方法上面,那么表示当前方法结束后,需要重新mock。
package com.superschool.test.demo;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.support.GenericXmlContextLoader;
@ContextConfiguration(locations = { "classpath:com/superschool/resource/spring/context/application/applicationContext.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
public class TestA {
@DirtiesContext
@Test
public void testMy() {
Assert.assertTrue(true);
}
}
@TestExecutionListeners
定义类级别的元数据配置。改注解应该同时配置一个TestContextManager。一般和ContextConfiguration注解同时使用,ContextConfiguration mock出来的TestContxt就是TestContextManager。
package com.superschool.test.demo;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
@ContextConfiguration(locations = { "classpath:com/superschool/resource/spring/context/application/applicationContext.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TestExecutionListeners({ TransactionalTestExecutionListener.class })
public class TestA {
@DirtiesContext
@Test
public void testMy() {
Assert.assertTrue(true);
}
}
@TransactionConfiguration
事物配置
transactionManager属性设置一个bean name,用来获取
PlatformTransactionManager 类型的bean。默认值是transactionManager。这个值应和tx:annotation-driven mode="proxy"
transaction-manager="transactionManager" />这里的相同。
defaultRollback 默认回滚属性。true表示测试结束恢复数据。
通常和ContextConfiguration同时存在。
package com.superschool.test.demo;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
@ContextConfiguration(locations = { "classpath:com/superschool/resource/spring/context/application/applicationContext.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TestExecutionListeners({ TransactionalTestExecutionListener.class })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@DirtiesContext
@Test
@Rollback(false)
public void testMy() {
Assert.assertTrue(true);
}
}
@BeforeTransaction表示在事物开始前运行,需要@Transactional注解才能有效
package com.superschool.test.demo;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
@ContextConfiguration(locations = { "classpath:com/superschool/resource/spring/context/application/applicationContext.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TestExecutionListeners({ TransactionalTestExecutionListener.class })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@BeforeTransaction
public void beforeTransaction() {
System.out.println("事物开始了");
}
@DirtiesContext
@Test
@Rollback(false)
public void testMy() {
Assert.assertTrue(true);
}
}
@AfterTransaction
类似
@NotTransactional
表示这个方法必须运行在一个非事物上下文下面。已经过时。
@Rollback
测试结束后是否回滚
配置在方法上面。
package com.superschool.test.demo;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
@ContextConfiguration(locations = { "classpath:com/superschool/resource/spring/context/application/applicationContext.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TestExecutionListeners({ TransactionalTestExecutionListener.class })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@DirtiesContext
@Test
@Rollback(false)
public void testMy() {
Assert.assertTrue(true);
}
}
一个例子
package com.superschool.test.demo;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import com.superschool.service.TestI;
@RunWith(value = SpringJUnit4ClassRunner.class)
//注意主力的classpath:后面以/开头,因为不以/开通,spring就会相对当前测试类所在的包往下递归找
@ContextConfiguration(locations = {
"classpath:/com/superschool/resource/spring/context/application/applicationContext.xml",
"classpath:/com/superschool/resource/spring/context/web/superschool-servlet.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@Resource
private TestI test;
@BeforeTransaction
public void beforeTransaction() {
System.out.println("事物开始了");
}
@DirtiesContext
@Test
@Rollback(false)
public void testMy() {
test.test();
Assert.assertTrue(true);
}
}
@IfProfileValue
当某个属性(properties形式的)存在或者给它指定一个值,只有值为这个值的时候才会执行这个测试。
package com.superschool.test.demo;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import com.superschool.service.TestI;
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:/com/superschool/resource/spring/context/application/applicationContext.xml",
"classpath:/com/superschool/resource/spring/context/web/superschool-servlet.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@Resource
private TestI test;
@BeforeTransaction
public void beforeTransaction() {
System.out.println("事物开始了");
}
@DirtiesContext
@Test
@Rollback(false)
@IfProfileValue(name = "java.vendor")
public void testMy() {
Assert.assertTrue(test.test());
}
@DirtiesContext
@Test
@Rollback(false)
@IfProfileValue(name = "java.vendor", value = "xxxxxx")
public void testMy1() {
Assert.assertTrue(test.test());
}
}
上面的例子定义了两个例子,一个只要定义了java.vendor属性就会执行。
一个是只有当属性java.vendor值等于xxxxxx才会执行。
也可以以组的方式存在
@IfProfileValue(name="test-groups", values={"unit-tests", "integration-tests"})
@Test
public void testProcessWhichRunsForUnitOrIntegrationTestGroups() {
// some logic that should run only for unit and integration test groups
}
只有有一个满足就可以了。
@ProfileValueSourceConfiguration
类级别的注解,指定IfProfileValue读取属性的实现类。默认是SystemProfileValueSource
@ExpectedException
预期测试将会抛出的异常。如果异常没有抛出或者类型不一样,将会测试失败。
@ExpectedException(SomeBusinessException.class)
public void testProcessRainyDayScenario() {
// some logic that should result in an Exception being thrown
}
@Timed
预期执行最大的时间。
spring的@Timed和junit的Timeout 区别是spring超时也不会立即停止,而是等待测试结束,计算总时间。包括重复的时间。
@Repeat
表示改测试将会重复执行N次
package com.superschool.test.demo;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import com.superschool.service.TestI;
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:/com/superschool/resource/spring/context/application/applicationContext.xml",
"classpath:/com/superschool/resource/spring/context/web/superschool-servlet.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@Resource
private TestI test;
@BeforeTransaction
public void beforeTransaction() {
System.out.println("事物开始了");
}
@Repeat(10)
@DirtiesContext
@Test
@Rollback(false)
public void testMy() {
Assert.assertTrue(test.test());
}
}
另外还支持spring的其他所有注解。
@Autowired
• @Qualifier
• @Resource (javax.annotation) if JSR-250 is present
• @Inject (javax.inject) if JSR-330 is present
• @Named (javax.inject) if JSR-330 is present
• @Provider (javax.inject) if JSR-330 is present
• @PersistenceContext (javax.persistence) if JPA is present
• @PersistenceUnit (javax.persistence) if JPA is present
• @Required
• @Transactional
TestContextManager是测试的入口。
TestExecutionListener定义了监视时间的API
上下文的管理一般不会去理会,但是有时候需要访问的话
可以
package com.superschool.test.demo;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import com.superschool.service.TestI;
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:/com/superschool/resource/spring/context/application/applicationContext.xml",
"classpath:/com/superschool/resource/spring/context/web/superschool-servlet.xml" }, loader = GenericXmlContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class TestA {
@Resource
private TestI test;
@Autowired
private ApplicationContext applicationContext;
@BeforeTransaction
public void beforeTransaction() {
System.out.println("事物开始了");
}
@Repeat(10)
@DirtiesContext
@Test
@Rollback(false)
public void testMy() {
Assert.assertTrue(test.test());
}
}
@ContextConfiguration(locations = {
"classpath:/com/superschool/resource/spring/context/application/applicationContext.xml",
"classpath:/com/superschool/resource/spring/context/web/superschool-servlet.xml" }, loader = GenericXmlContextLoader.class)
这里的loader=GenericXmlContextLoader.class可以不需要,因为它就是默认加载器。
默认情况下会加载当前包下面的MyTest-context.xml
如你的测试类是com.example.MyTest
那么会加载classpath:/com/example/MyTest-context.xml
另外如果要自己写classpath应该是classpath:/xx/xxxx/xxxx而不是classpath:xx/xxxx/xxxx
。因为如果写classpath:/xx/xxxx/xxxx它会在当前包下面查找xx.xxxx子包的xxxx文件
正常情况下ApplicationContext只加载一次,这个测试类之后的测试都重用一个applicationcontext。
inheritLocations属性 表示从父类加载。
默认是true
@RunWith(SpringJUnit4ClassRunner.class)
// ApplicationContext will be loaded from "/base-context.xml" in the root of the classpath
@ContextConfiguration("/base-context.xml")
public class BaseTest {
// class body...
}
// ApplicationContext will be loaded from "/base-context.xml" and "/extended-context.xml"
// in the root of the classpath
@ContextConfiguration("/extended-context.xml")
public class ExtendedTest extends BaseTest {
// class body...
}
默认情况下会自动配置一个DependencyInjectionTestExecutionListener的TestExecutionListeners。它会自动注入属性。
如
@RunWith(SpringJUnit4ClassRunner.class)
// specifies the Spring configuration to load for this test fixture
@ContextConfiguration("daos.xml")
public final class HibernateTitleDaoTests {
// this instance will be dependency injected by type
@Autowired
private HibernateTitleDao titleDao;
public void testLoadTitle() throws Exception {
Title title = this.titleDao.loadTitle(new Long(10));
assertNotNull(title);
}
}
@RunWith(SpringJUnit4ClassRunner.class)
// specifies the Spring configuration to load for this test fixture
@ContextConfiguration("daos.xml")
public final class HibernateTitleDaoTests {
// this instance will be dependency injected by type
private HibernateTitleDao titleDao;
@Autowired
public void setTitleDao(HibernateTitleDao titleDao) {
this.titleDao = titleDao;
}
public void testLoadTitle() throws Exception {
Title title = this.titleDao.loadTitle(new Long(10));
assertNotNull(title);
}
}
这种方式完全符合spring的注入规则。包括Resource注解。Qualifier注解
默认情况下会自动配置一个TransactionalTestExecutionListener。但是你必须设置的PlatformTransactionManager bean
如
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
另外还要加入
@Transactional
测试支持类
org.springframework.test.context.junit4包
运行器
@RunWith(SpringJUnit4ClassRunner.class)
会自动加载配置
发表评论
-
Spring 定时任务,cron表达式,@Scheduled cron表达式
2016-04-25 15:48 5296一个cron表达式有至少6 ... -
spring mvc list
2015-12-14 10:28 1286我使用这样无法传入 @requestMapping(" ... -
Unable to locate Spring NamespaceHandler for XML schema namespace
2015-09-23 14:00 2323org.springframework.beans.facto ... -
关于使用s.url jstl的上下文
2015-08-16 13:28 920比如 [@s.url '/'/]index.html?cote ... -
Spring 属性占位符配置器 PropertyPlaceholderConfigurer
2015-08-02 12:43 2084<!-- 属性配置文件读 ... -
FactoryBean接口
2014-09-30 14:05 908实现了FactoryBean接口的bean不是简单的一个bea ... -
国际化之MessageSourceAware和MessageSourceAccessor
2014-01-06 23:13 2856先看接口MessageSourceAware 该接口的注释中 ... -
spring 惯例优先原则
2013-07-22 09:46 1213惯例优先原则(convention over configur ... -
ant path匹配
2013-07-22 09:40 2175spring和ant path实现相关的主要类有两个 org. ... -
springmvc action方法中参数具有@ModelAttribute与不具有的区别
2012-12-14 09:36 4117在springmvc的参数解析中,发现具有@ModelAttr ... -
util包
2012-12-05 13:50 1109spring的util基本上都在springframework ... -
url,请求相关帮助类UrlPathHelper
2012-11-29 11:18 2520org.springframework.web.util.Ur ... -
整站国际化方案
2012-11-28 17:46 1111当前常见的实现方式,主要由两种方案实现 1.通过locale ... -
spring的三种注入方式
2012-11-20 17:30 18691.通过bean的property子元 ... -
spring AnnotationUtils 注解工具
2011-12-08 11:27 1304spring AnnotationUtils 注解工具 -
GenericCollectionTypeResolver,用于获取list或者map等元素的类型
2011-12-07 16:17 1312GenericCollectionTypeResolver,用 ... -
属性编辑器
2011-12-05 18:19 1081我自定义了一个类型,然后设置了一个属性编辑器,注册的class ... -
iframe下面的session问题
2011-12-04 19:52 5321在写iframe完成长连接获取上传状态的时候,有两次请求,一次 ... -
mvc之类的驱动原理
2011-12-01 09:34 1098<mvc:annotation-driven /> ... -
Couldn't access current invocation
2011-10-20 20:44 1895做了一个aop的日志记录器,但是在运行的时候出现了日志信息 服 ...
相关推荐
本资料“基于PHP的Unit测试框架”将深入探讨如何使用这些框架进行有效的单元测试。 PHP的Unit测试框架指的是专门用于测试PHP代码的工具,如PHPUnit,它是PHP中最广泛使用的单元测试框架之一。PHPUnit提供了丰富的...
【标题】"基于PHP的Unit测试框架源码.zip" 提供的是一个用于PHP开发的单元测试框架的源代码。在软件开发中,单元测试是一种重要的质量保证手段,它允许开发者针对程序中的最小可测试单元——通常是一个函数或方法...
陕旅版三年级上册unit测试题.pdf
人教版五年级英语下册unit测试题终审稿).pdf
本教程将深入探讨Java Unit测试的基本概念、工具和实践技巧。 一、单元测试的原理与目的 单元测试是针对程序中的最小可测试单元进行的,如方法或函数。其目的是确保代码的每一个部分都能单独工作,以便于发现和修复...
这篇文档是针对PEP小学四年级英语上册Unit 2的测试题,旨在评估学生对英语基础知识的理解和听力技能的掌握。测试分为听力和读写两大部分,涵盖多个语言学习的关键方面。 一、听力部分: 1. 听一听,圈一圈:这部分...
六年级上册英语剑桥Join in版Unit1 School is great fun! 单元测试卷(含答案).pdf
在进行MR Unit测试时,我们需要编写JUnit测试类,每个测试用例对应MapReduce作业的一个特定方面,例如Mapper或Reducer的正确性。 4. mrunit-1.1.0-hadoop2.jar:MRUnit是专门为MapReduce设计的单元测试库,它提供了...
8. **jenkins.xml**:Jenkins是持续集成服务器,这个文件可能包含了配置信息,允许开发者将flex-unit测试集成到Jenkins的持续集成流程中,自动运行测试并报告结果。 9. **FlexUnit4AirCIListener** 和 **FlexUnit4...
**C++ Unit测试框架——CppUnit详解** C++ Unit(CppUnit)是一个开源的单元测试框架,用于编写和运行C++代码的测试用例。它借鉴了JUnit在Java中的成功经验,为C++开发者提供了方便的测试工具。在这个文档中,我们...
编写Test::Unit测试的基本步骤如下: 1. **引入Test::Unit**:确保Test::Unit在你的Ruby环境中可用。 2. **请求测试支持**:在测试脚本中,通过`require 'test/unit'`引入Test::Unit库。 3. **创建测试类**:创建...
这篇文档是针对三年级学生设计的一份英语测试题,主要涵盖了译林版三年级英语下册unit1至unit3的内容。这份试卷分为听力和笔试两大部分,旨在检查学生对基本词汇、短语、句子的理解以及听力反应能力。 听力部分: 1...
### Visual Unit单元测试使用教程知识点总结 #### 一、单元测试概述 - **定义与重要性**: - **定义**:单元测试是软件开发过程中的一种测试方法,它针对程序中的最小可测试单元进行验证。 - **必要性**:通过...
本测试报告使用Visual Unit测试工具,直接解压"Visualunit1.4.5”文件,并点击"setup"进行安装。安装完成后形成的文件将在最后安装目录结果中显示。点击运行Visual Unit主界面,将显示测试工程的建立和配置。 三、...
VisualUnit是一款针对C++程序员的单元测试工具,它为Visual Studio环境提供了方便的集成,使得开发者能够在不改变原有开发流程的情况下,轻松地进行单元测试。 VisualUnit的应用使得单元测试变得更加高效和便捷。...
这篇文档是针对小学四年级学生的一份开心英语单元测试题,涵盖了Unit 5到Unit 6的内容。测试主要考察学生的听力理解能力,包括选择题、排序题和填空题,旨在检验学生对单词发音、词汇识别、语法以及对话理解的掌握...
在软件开发过程中,单元测试(Unit Testing)是至关重要的一个环节,它构成了整个测试金字塔的基础。"UNit_Test单元测试课件"显然是一份详细讲解单元测试的资料,旨在帮助开发者理解和掌握这一关键技能。单元测试是...
这篇文档是针对小学五年级上学期英语学习的Unit5-Unit6测试卷,旨在检验学生对这两个单元的掌握情况。试卷包含听力部分,主要考察学生的英语听力理解和口语应用能力。 一、听力部分的第一个环节是听录音,找出所...
我们可以将这个逻辑封装进一个JavaScript对象,并用JS Unit测试该对象。 JavaScript对象封装的优点是: * 使代码更加组织化和易于维护 * 使测试更加容易和高效 * 使代码更加灵活和可扩展 在JavaScript对象封装中...
这篇文档是针对鲁教版五四制九年级上册英语Unit 1的一份单元测试卷,主要考察学生的英语听力理解能力。测试卷包含了四个部分:听句子选择恰当的答语、听小对话选择正确答案、听长对话选择正确答案以及听短文补全表格...