We have a Web Application Project (dozens actually..) that has a testing project attached to it. In the testing project I have a simple unit test which exercises a couple of methods.
我们有一个Web应用程序项目(实际上有几十个......),它附带了一个测试项目。在测试项目中,我有一个简单的单元测试,它练习了几种方法。
Running locally, the unit test executes and works.
在本地运行,单元测试执行并运行。
However, when our TFS Build server attempts to execute the test, it fails with a error about an invalid path for the AspNetDevelopmentServerHost attribute. Other team members can execute it just fine.
但是,当我们的TFS构建服务器尝试执行测试时,它会失败,并显示有关AspNetDevelopmentServerHost属性的无效路径的错误。其他团队成员可以很好地执行它。
The problem is that the root of my TFS Workspace is set to c:\projects\ One of the team members has theirs set to c:\tfs2008\ The TFS Build server on the other hand sets the pathToWebRoot variable to "c:\blahblah\Release_PublishedWebsites..." Which results in a bad path.
问题是我的TFS工作区的根设置为c:\ projects \其中一个团队成员将其设置为c:\ tfs2008 \另一方面,TFS Build服务器将pathToWebRoot变量设置为“c:\ blahblah \ Release_PublishedWebsites ...“这导致了一条糟糕的道路。
Due to the number of projects we have, I can't have everyone reset an environment variable every time they switch projects.
由于我们拥有的项目数量众多,我不能让每个人在每次切换项目时重置环境变量。
So, what are the best practices with regards to unit testing web projects in a team environment? The MSDN site article was in true microsoft fashion less than helpful.
那么,在团队环境中对Web项目进行单元测试的最佳实践是什么? MSDN站点文章真正的微软时尚不太有用。
3 个解决方案
#1
you should specify the string %pathtowebroot%\\WebSiteName
in the ,pathToWebApp
parameter of the AspNetDevelopmentServer
or AspNetDevelopmentServerHost
attribute.
您应该在AspNetDevelopmentServer或AspNetDevelopmentServerHost属性的pathToWebApp参数中指定字符串%pathtowebroot%\\ WebSiteName。
#2
We use:
<TestMethod(), _
HostType("ASP.NET"), _
AspNetDevelopmentServerHost("$(SolutionDir)\\MyWebProject", "/"), _
UrlToTest("http://localhost:44444/")>
Public Sub Test()
AssertStuff();
End Sub
The $(SolutionDir)
means it works fine in everyone's environment, and all the tests can be checked in. We do have to change it each time we automatically create a new test, but we're writing the test anyway, so it's not too much of a hardship.
$(SolutionDir)意味着它可以在每个人的环境中正常工作,并且可以检查所有测试。我们每次自动创建新测试时都必须更改它,但我们仍在编写测试,所以它也不是很多困难。
#3
It's possible to set environment variables during the build to alter the path and still have it work in a local environment.
可以在构建期间设置环境变量以更改路径,并使其在本地环境中工作。
- How to: Parameterize the URL for a Web Performance Tests Web Server
- Testing Web Sites and Web Services in a Team Environment
如何:参数化Web性能测试Web服务器的URL
在团队环境中测试网站和Web服务
#1
you should specify the string %pathtowebroot%\\WebSiteName
in the ,pathToWebApp
parameter of the AspNetDevelopmentServer
or AspNetDevelopmentServerHost
attribute.
您应该在AspNetDevelopmentServer或AspNetDevelopmentServerHost属性的pathToWebApp参数中指定字符串%pathtowebroot%\\ WebSiteName。
#2
We use:
<TestMethod(), _
HostType("ASP.NET"), _
AspNetDevelopmentServerHost("$(SolutionDir)\\MyWebProject", "/"), _
UrlToTest("http://localhost:44444/")>
Public Sub Test()
AssertStuff();
End Sub
The $(SolutionDir)
means it works fine in everyone's environment, and all the tests can be checked in. We do have to change it each time we automatically create a new test, but we're writing the test anyway, so it's not too much of a hardship.
$(SolutionDir)意味着它可以在每个人的环境中正常工作,并且可以检查所有测试。我们每次自动创建新测试时都必须更改它,但我们仍在编写测试,所以它也不是很多困难。
#3
It's possible to set environment variables during the build to alter the path and still have it work in a local environment.
可以在构建期间设置环境变量以更改路径,并使其在本地环境中工作。
- How to: Parameterize the URL for a Web Performance Tests Web Server
- Testing Web Sites and Web Services in a Team Environment
如何:参数化Web性能测试Web服务器的URL
在团队环境中测试网站和Web服务