11-3URLTestDemo??????????URL???????
???????????? ???????[ 2014/5/19 13:38:16 ] ????????URL??????? TestDemo
????4????????????URL????????????11-3URLTestDemo????У???Global.asax.cs???????RegisterRoutes??????????£?
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("MyRoute"?? "{controller}/{action}");
}
|
???????????RegisterRoutes??????????????????Create Unit Tests?????????????????????????????URLTestDemo.UnitTests?в???????????
MvcApplicationTest.cs??????????????????MvcApplicationTest???е???????????????????£?
namespace URLTestDemo.UnitTests
{
[TestClass()]
public class MvcApplicationTest
{
private HttpContextBase CreateHttpContext(string targetUrl=null??
string httpMethod = "GET")
{
Mock<HttpRequestBase> mockRequest = new Mock<HttpRequestBase>();
mockRequest.Setup(m => m.AppRelativeCurrentExecutionFilePath).Returns(targetUrl);
mockRequest.Setup(m => m.HttpMethod).Returns(httpMethod);
Mock<HttpResponseBase> mockResponse = new Mock<HttpResponseBase>();
mockResponse.Setup(m => m.ApplyAppPathModifier(
It.IsAny<string>())).Returns<string>(s => s);
Mock<HttpContextBase> mockContext = new Mock<HttpContextBase>();
mockContext.Setup(m => m.Request).Returns(mockRequest.Object);
mockContext.Setup(m => m.Response).Returns(mockResponse.Object);
return mockContext.Object;
}
private void TestRouteMatch(string url?? string controller??
string action?? object routeProperties = null??
string httpMethod = "GET")
{
//????
RouteCollection routes = new RouteCollection();
MvcApplication.RegisterRoutes(routes);
//????
RouteData result = routes.GetRouteData(CreateHttpContext(url?? httpMethod));
//????
Assert.IsNotNull(result);
Assert.IsTrue(TestIncomingRouteResult(result?? controller?? action?? routeProperties));
}
private bool TestIncomingRouteResult(RouteData routeResult??
string controller?? string action?? object propertySet = null)
{
Func<object?? object?? bool> valCompare = (v1?? v2) =>
{
return StringComparer.InvariantCultureIgnoreCase.Compare(v1?? v2) == 0;
};
bool result = valCompare(routeResult.Values["controller"]?? controller)
&& valCompare(routeResult.Values["action"]?? action);
if (propertySet != null)
{
PropertyInfo[] propInfo = propertySet.GetType().GetProperties();
foreach (PropertyInfo pi in propInfo)
{
if (!(routeResult.Values.ContainsKey(pi.Name) &&
valCompare(routeResult.Values[pi.Name]?? pi.GetValue(propertySet?? null))))
{
result = false;
break;
}
}
}
return result;
}
private void TestRouteFail(string url)
{
//????
RouteCollection routes = new RouteCollection();
MvcApplication.RegisterRoutes(routes);
//????
RouteData result = routes.GetRouteData(CreateHttpContext(url));
//????
Assert.IsTrue(result == null || result.Route == null);
}
[TestMethod]
public void TestIncomingRoutes()
{
TestRouteMatch("~/Admin/Index"?? "Admin"?? "Index");
TestRouteMatch("~/One/Two"?? "One"?? "Two");
TestRouteFail("~/Admin/Index/Segment");
TestRouteFail("~/Admin");
}
}
}
|
????5???????????????????Test -> Run -> All Tests in Solution????е???????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
iOS???????mocha??chai??sinon??istanbul???????????????????????????????????????д?????Java????????7??????Android?????????Robolectric3.0????(?)???Kiwi?????????????????????????????????Python?????????????????????????????????????Controller????????д?????????10???????????????????Angular????????????Component??Directive??Pipe ???ServiceAndroid????????????????????????????????--Mockito??????iOS UnitTest???????Vue?????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????