一、stub unit test
“test stub”命令创建JUnit测试
1、假定已经创建service层代码
package org.rooina.coursemanager.service; import java.math.BigDecimal; import org.springframework.beans.factory.annotation.Autowired; public class DefaultTaxCalcService implements TaxCalcService { private BigDecimal taxRate; @Autowired public DefaultTaxCalcService(BigDecimal taxRate) { this.taxRate = taxRate; } @Override public BigDecimal calculateTax(BigDecimal price) { return price.multiply(taxRate); } }
2、创建测试脚本
roo> test stub --class ~.service.DefaultTaxService
3、产生测试代码
package org.rooina.coursemanager.service; import org.junit.Test; public class DefaultTaxCalcServiceTest { private DefaultTaxCalcService defaultTaxCalcService = ➥ new DefaultTaxCalcService(); @Test public void calculateTax() { org.junit.Assert.assertTrue(true); } }
4、更新测试代码
package org.rooina.coursemanager.service; import java.math.BigDecimal; import junit.framework.Assert; import org.junit.Test; public class DefaultTaxCalcServiceTest { private DefaultTaxCalcService defaultTaxCalcService = new DefaultTaxCalcService(new BigDecimal("0.02")); @Test public void calculateTax() { BigDecimal price = new BigDecimal("50"); BigDecimal taxAmount = defaultTaxCalcService.calculateTax(price); Assert.assertEquals("Tax rate invalid", new BigDecimal("1.00"), taxAmount); } }
二、任意测试
测试任意类时
1、脚本代码
roo> class --class ~.web.BillingServiceSystemTest ➥ --path SRC_TEST_JAVA
2、测试代码
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext*.xml") public class TaskServiceSystemTest { @Autowired private TaskService service; long studentId; @Test @Transactional public void testTask() { TaskDataOnDemand taskDod = new TaskDataOnDemand(); Task task = taskDod.getRandomTask(); Long taskId = task.getId(); Task task1 = service.findTask(taskId); Assert.assertNotNull(task1); } }
相关推荐
Manning Spring Roo in Action 完整版。
spring roo 官方文档。很权威的东西。最新版本1.1.5的。
spring roo是快速开发java的框架,支持spring mvc/security/tiles/webflow/test,也可以自己修改。
在使用 Spring ROO的时候 除了要在eclipse中安装Spring ROO 插件以外 还在要在电脑上配置 Spring ROO环境 (和jdk的环境配置一样)
NULL 博文链接:https://ximeng1234.iteye.com/blog/2205872
NULL 博文链接:https://moonshinewoo.iteye.com/blog/1835032
spring的新技术,使开发变的更简单,更明了。在spring的基础上,推出了roo。
SpringRoo 官方文档-版本2.0.0.RC1
spring-roo-2.0.0.RC1.zip
spring roo actionspring roo actionspring roo actionspring roo actionspring roo actionspring roo actionspring roo action
spring roo的eclipse工程。可象普通java工程一样调试,跟Felix无关。注意其中的.lanches文件需要copy到你的eclipse workspace的.metadata\.plugins\org.eclipse.debug.core下
springroo快速学习
具体可以查看我的博客 http://blog.csdn.net/qiumeng_1314/article/details/77711867
Spring Roo - Reference Documentation
spring-roo-1.0.0.A2 Spring Roo 是SpringSource新的开放源码技术,该技术主要面向企业中的Java开发者,使之更富有成效和愉快的进行开发工作,而不会牺牲工程完整或灵活性。无论你是一个新的Java开发人员或经验丰富...
spring-roo里面有打包,还有需要的东西,这是release版本
s-springroo2-sample_code
Spring ROO 1.1.0 升级到 1.1.1中文文档
企业应用开发平台 Spring Roo ,Spring Roo 是针对 Java™ 技术的一个轻量级生产力工具,可快速便捷地开发基于 Spri...
vaadin,spring-roo,war包和源码