`

SpringTest

阅读更多

1.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.tome.testService;
import javax.annotation.Resource;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;
import org.testng.annotations.BeforeMethod;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import com.google.common.collect.Maps;
import com.tome.model.HeartRate;
import com.tome.service.HeartRateService;
import com.tome.service.UserService;
@RunWith(SpringJUnit4ClassRunner.class)//让junit工作在spring环境中
@ContextConfiguration({"classpath:spring.xml","classpath:spring-mvc.xml"})//在classes中spring的配置文件
//transactionManager表示在spring配置文件中所声明的事务对象mvn install -Dmaven.test.skip=true  
//defaultRollback=true表示操作会自动回滚,这样你在单元测试中所作的操作都不会影响数据库中的数据
@TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true)
@Transactional
@WebAppConfiguration
public class TestController extends AbstractTestNGSpringContextTests
{
 @Autowired
 private WebApplicationContext wac;//WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(ServletContext);
 private MockMvc mockMvc; 
   @BeforeMethod 
    public void setUp() { 
   
        mockMvc =MockMvcBuilders.webAppContextSetup(this.wac).build();
    
   
   @org.testng.annotations.Test
    public void accessTomeController(String path, String value) throws Exception { 
  /**
   
   * this.mockMvc.perform(get("/tome/testHello")
                .accept(MediaType.TEXT_HTML))
                .andExpect(status().isOk())
                .andExpect(view().name("helloworld"))
                .andExpect(MockMvcResultMatchers.model().attribute("user", "zhuyuping"));
   
   
   
   *  this.mockMvc.perform(get("/json/testJson")
                .accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.user").value("朱遇平"));
   
   
   
   
   */
        mockMvc.perform(get("/ckset")).andExpect(status().isOk()); //这是测试没有返回结果的方法测试 
    
}
 
 
 
 

 

 

2.

@WebAppConfiguration
@RunWith(value = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:config/applicationContext.xml","classpath:config/applicationContext-jpa.xml","classpath:config/spring-mvc.xml"})
public class LiquidationProjectTypeRulesTemplateServiceTest {

	@Autowired
	private LiquidationProjectTypeRulesTemplateService service;
	
	@Test
	public void testAddLiquidationProjectTypeRulesTemplate() {
	  LiquidationProjectTypePojo pojo = new LiquidationProjectTypePojo();
	 // pojo.setProjectId(1L);
	  pojo.setProjectTypeId(1L);
	  pojo.setProjectRatio(10);
	  pojo.setPersonnalRatio(10);
	  pojo.setSmallThreshold1("1");
//	  pojo.setBigThreshold1(3f);
	  pojo.setRatio1(1);
//	  
//	  pojo.setSmallThreshold2(4f);
//	  pojo.setBigThreshold2(10f);
//	  pojo.setRatio2(20f);
//	  
//	  pojo.setSmallThreshold3(11f);
//	  pojo.setBigThreshold3(13f);
//	  pojo.setRatio3(30f);
	  List<LiquidationProjectTypePojo> list = new ArrayList<LiquidationProjectTypePojo>();
	  list.add(pojo);
	  //service.addLiquidationProjectTypeRulesTemplate(list);
	}
	
	@Test
	public void query(){
		// service.getLiquidationProjectType();
		try {
			service.getLiquidationProjectData();
		} catch (HossException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//System.out.println(Jsonp.success(list));
	}

}

 

分享到:
评论

相关推荐

    SpringTest_springtest_spring_java_Framework_

    "SpringTest_springtest_spring_java_Framework_"这个标题暗示了我们讨论的是关于Spring框架的测试方面,可能是使用Spring进行单元测试或集成测试的一些实践。 描述中的“简单小应用,实现了一些基本的功能”可能是...

    Spring test

    Spring Test是Spring框架的一个重要组成部分,它为Java开发者提供了强大的测试支持,涵盖了单元测试、集成测试以及端到端测试的方方面面。Spring Test旨在简化应用程序的测试工作,通过与JUnit和其他测试框架结合,...

    Springtest

    本教程将基于"Springtest"这个项目,深入浅出地探讨Spring框架的基础知识和应用。 一、Spring概述 Spring是一个开源的Java企业级应用程序框架,由Rod Johnson创建,主要目标是简化Java EE开发。它提供了全面的编程...

    SpringTest cookie

    当我们谈论“SpringTest cookie”时,这可能指的是使用Spring Test模块进行Cookie相关的单元测试和集成测试。 Spring Test是Spring框架的一部分,专门用于支持测试Spring驱动的应用程序。它提供了一组工具,允许...

    spring test学习2

    Spring Test是Spring框架的一部分,专为测试Spring应用而设计,它提供了丰富的功能,使得开发者能够更轻松、更高效地对Spring驱动的应用进行单元测试和集成测试。在本篇中,我们将深入探讨Spring Test的关键概念、...

    spring test

    Spring Test是Spring框架中的一个重要组成部分,它为Java开发者提供了强大的测试工具,用于验证Spring应用程序的配置和行为。在本文中,我们将深入探讨Spring Test的核心概念、功能以及如何使用它进行有效的单元测试...

    mybatis+spring+springtest

    【标题】"mybatis+spring+springtest" 涉及到的是在Java开发中集成MyBatis、Spring以及Spring Test框架的知识点。这个标题暗示了我们正在讨论如何在项目中整合这三个强大的工具来实现数据访问层(DAO)的自动化测试...

    Java Spring test

    a java spring test in invertion of control a java spring test in invertion of control

    spring+redis作为缓存,带springTest配置

    在这个项目中,“spring+redis作为缓存,带springTest配置”旨在展示如何在Spring应用中集成Redis作为缓存,并利用Spring Test进行测试。 首先,我们需要理解Spring框架。Spring是一个全面的企业级应用开发框架,它...

    Spring Test与开发者测试(10)

    在本篇中,我们将深入探讨Spring Test框架以及它在开发者测试中的应用,特别是与Redis集成的测试场景。Spring Test是Spring框架的一部分,为Spring应用程序提供了强大的单元测试和集成测试支持。我们将通过分析提供...

    Spring test样例及实现

    提供一个很好的测试spring的样例,包括如何配置,详细的测试方案,还有相关代码展示

    SpringTest(3).zip

    SpringTest(3).zip是一个可能包含与Spring框架相关的测试材料的压缩文件。Spring是一个广泛使用的Java企业级应用开发框架,特别适用于构建可测试、模块化和松耦合的应用程序。这个压缩包可能包括了源代码、配置文件...

    SpringTest.zip

    《Spring MVC 框架详解及实战指南》 在Java Web开发领域,Spring MVC框架以其强大的功能和灵活性,成为开发者们的首选。本指南将深入探讨Spring MVC的核心概念、配置以及实际应用,帮助新手快速上手。 一、Spring ...

    springtest.rar

    《Spring框架中的依赖注入实践——基于“springtest.rar”案例分析》 在Java开发领域,Spring框架因其强大的功能和灵活性而备受青睐。其中,依赖注入(Dependency Injection,简称DI)是Spring的核心特性之一,它极...

    javaweb主流框架整合开发springtest例子

    本示例“javaweb主流框架整合开发springtest例子”旨在介绍如何将Spring与其他技术进行整合,以提升开发效率和应用质量。在"开发者突击"这个主题下,我们将深入探讨Spring的核心概念以及如何利用SpringTest进行单元...

Global site tag (gtag.js) - Google Analytics