Eclipse TestNG

1.安裝TestNG 插件

  在Eclipse Marketplace裏安裝插件,目前最新插件是6.9版本,要求的JDK是1.7,,否則會不能執行。

這裏指定JDK,



2.編寫測試代碼:

  此項目基於Spring 的maven工程:

 

@ContextConfiguration(locations = { "classpath*:config/spring/spring-aop.xml",
        "classpath*:config/spring/spring-web.xml",
         "classpath*:config/spring/spring-dal.xml",
        "classpath*:spring-datasource-test.xml",
        "classpath*:config/spring/spring-init.xml",
        "classpath*:config/spring/spring-tsp-framework.xml",
        "classpath*:config/spring/spring-cache.xml",
        "classpath:config/spring/spring-tsp.xml",
        "classpath*:config/spring/spring-jms.xml", 
        "classpath*:config/spring/spring-log.xml"      
        })
@Test
public class BaseTest extends AbstractTestNGSpringContextTests {}
上面的@ContextConfiguration用來配置數據源等信息

此時可以編寫測試類:

public class IDiyServiceTest extends  BaseTest {
	
	@Resource( name = "diyServiceImpl" )
	private IDiyService iDiyService;
	
  @Test
  public void testGetDiyInfoByProductId() {
	  ProductDetailRequestVo productDetailRequestVo=new ProductDetailRequestVo();
	  productDetailRequestVo.setProductType(2);
	  productDetailRequestVo.setProductId(5004635);
	  productDetailRequestVo.setRequestSourceCode(2);
	  ResponseVo resp=iDiyService.getDiyInfoByProductId(productDetailRequestVo);
	  Assert.notNull(resp.getData());
	  
  
  }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章