作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 ASP.NET MVC 应用程序。其HttpApplication
看起来像这样:
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
//Do some sort of initialisation. Set the DependencyResolver.
}
}
DependencyResolver
与它互动。访问
DependencyResolver
看起来很简单,因为我可以调用
DependencyResolver.Current
.但是,我还没有弄清楚如何让应用程序初始化逻辑运行。
new MvcApplication().Init()
,但这似乎不会触发
Application_Start
方法调用。我尝试从
MvcApplication
继承并提供直接调用
Application_Start
的权限,但是由于 ASP.NET MVC 的异常而失败。
最佳答案
您可以使用 Selenium WebDriver 进行 MVC 应用程序的集成测试。您可以通过编写 Web 浏览器要执行的操作以编程方式与应用程序 UI 交互。然后可以从 MSTest 运行集成测试,以便您可以针对 UI 编写断言。这是 Selenium 的文档 http://docs.seleniumhq.org/docs/03_webdriver.jsp
这是一个代码示例:
[TestMethod]
public void runUITest()
{
driver = new FirefoxDriver(); //launches a Firefox window so you can observe the test run
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 7));
driver.Navigate().GoToUrl("http://localhost/yourWebApp"));
//assert something
Assert.IsTrue(driver.FindElement(By.XPath("//fieldset[@id='YourControl']/div/div[2]/label/span/span")).Displayed);
//find an element and click it
driver.FindElement(By.Id("FormSubmitButton")).Click();
}
关于.net - 如何以编程方式启动 ASP.NET MVC 应用程序并与之交互?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20318415/
我是一名优秀的程序员,十分优秀!