.NET程序员项目开发必知必会—Dev环境中的集成测试用例执行时上(4)
来源:未知 责任编辑:责任编辑 发表时间:2015-05-17 20:34 点击:次
我们加入了一个很重要的测试实例运行时方法InitTestInstance,该方法会在测试用例每次实例化时先执行,在方法内部有一个用来检查当前测试用例运行的环境
this.CheckCurrentTestCaseIsRun(this.serviceInstance);//check current test case .,我们转到基类中。
using System; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace OrderManager.Test { public abstract class ProductServiceIntegrationBase { /// <summary> /// service address. /// </summary> protected const string ServiceAddressForDev = "http://dev.service.ProductService/"; /// <summary> /// get service address. /// </summary> protected const string ServiceAddressForPrd = "http://Prd.service.ProductService/"; /// <summary> /// service address. /// </summary> protected const string ServiceAddressTest = "http://Test.service.ProductService/"; /// <summary> /// Test context . /// </summary> public TestContext TestContext { get; set; } /// <summary> /// is check is run for current test case. /// </summary> protected void CheckCurrentTestCaseIsRun(ProductService.Contract.ProductServiceClient testObject) { if (testObject.ServiceAddress.Equals(ServiceAddressForPrd))// Prd 环境,需要小心检查 { if (this.TestContext.TestName.Equals("ProductService_DeleteProductSearchIndex_Test")) Assert.IsTrue(false, "当前测试用例连接的环境为PRD,请停止当前用例的运行。"); } else if (testObject.ServiceAddress.Equals(ServiceAddressTest))//Test 环境,检查约定几个用例 { if (this.TestContext.TestName.Equals("ProductService_DeleteProductSearchIndex_Test")) Assert.IsTrue(false, "当前测试用例连接的环境为TEST,为了不破坏TEST环境,请停止用例的运行。"); } } } }
相关新闻>>
- 发表评论
-
- 最新评论 更多>>