Asp.net mvc 如何对global.asax文件进行单元测试?
在我的应用程序中,一些变量在应用程序启动时初始化。例如,在global.aspx文件中Asp.net mvc 如何对global.asax文件进行单元测试?,asp.net-mvc,unit-testing,Asp.net Mvc,Unit Testing,在我的应用程序中,一些变量在应用程序启动时初始化。例如,在global.aspx文件中 Application_start() { //velocityhelper.TemplateLocatio is static class. VelocityHelper.TemplateLocation = ConfigurationHelper.ContentLocation + "/" + ConfigurationHelper.CultureId + "/" + "
Application_start()
{
//velocityhelper.TemplateLocatio is static class.
VelocityHelper.TemplateLocation = ConfigurationHelper.ContentLocation + "/"
+ ConfigurationHelper.CultureId + "/" + "Templates/";
}
当我们访问templatelocation变量时,它将始终返回null。请告诉我如何初始化此模板位置。您不能在Global.asax中对代码进行单元测试,因为您需要一个HttpApplication来执行它。另一方面,您可以将此代码放在一个单独的方法中,然后对该方法进行单元测试