Visual Studio 2005, Web Sites, and Test-Driven Development

After doing lots of spiking and visual design on a Visual Studio 2005 web site project, I set out to write some production code for the site. I've done some TDD-based component development already on this project, but this was my first foray into writing actual logic (humble dialog style) in the web site project itself. It didn't take long to hit a big snag.

I typically like to put my unit tests in the same assembly being tested. That's always worked well in VS2003, even in web projects, so my first thought was to take the same approach in VS2005. The flaw in that plan is that "building" the web site doesn't generate an assembly that I can point the NUnit test runner at (the assembly ends up in the Temp. ASP.NET Files folder, which isn't too helpful for testing). Oops.

The only solution I've come up with so far is to put the testable UI logic in a separate assembly. Are there any other options that I'm missing?

2 Comments

  • With VSTS you can create a "Test Project" that can contain unit tests for classes, as well as UI tests for web-pages (it also includes a built-in UI test recorder for ASP.NET). The nice thing about both of these is that when run, they run in the context of a web-server -- so you'll get more accurate results than running in a separate command-line environment.



    Note that if you use the "Publish WebSite" option you can also pre-compile the site into assemblies underneath the \bin directory. This would allow you to still use a NUnit test runner to execute them as well. With Beta1 the assembly names underneath \bin are not consistent -- which makes this hard. But with Beta2 the names are consistent and so you will be able to use this approach.



    Hope this helps,



    Scott

  • Scott,

    Thanks for the info. So does that mean VSTS test projects can test classes defined in a web project? It knows how to find the compiled assembly for the site?



    Ah, if only the base Visual Studio platform had included unit testing, life would be so fine. :)



    Is there any way to get the IDE to automate the publish whenever you build? If not, I'm not sure if I can use that technique.



Comments have been disabled for this content.