How are people unit testing in ASP.NET 2.0?

E

Eric

I've spent some time this morning looking into unit testing frameworks
for ASP.NET 2.0, but none seem satisfactory. I don't have Visual
Studio Team Edition, so apparently I can't use Microsoft's solution,
and TestDriven.net has no support for web applications.

The best I have found is to use NUnit on the .dll that is created when
the site is published. However, I have found that this .dll is not
updated with each publish, instead new "App_Web_variousgarbage.dll"
files are added to the folder. NUnit doesn't pick up the changes from
those files, so the tests remain the same from the first publish. The
problem is solved if I delete the contents of the folder, but that
leaves me with a rather unsatisfactory 3 step process (Delete, Publish,
Run Tests). There has to be a better way!

What are other people using to run unit tests on ASP.NET 2.0? Ideally,
I'm looking for a one click solution.

Thanks,
Eric
 
K

Karl Seguin

Well first, you can use the Web Application Project (free)
http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx to make 2005 web
projects behave like 2003 - which'll solve your assembly name issue. I use
it almost exclusively.

Secondly, I hardly test my presentation layer - it's too much of a hassle
for too little gain. Unit tests work better against your domain layer, your
data access layer and database integration. I do test class files within
web projects (as best I can), but not my aspx and .aspx.cs files...If that's
what you want,the Web Application Project will work for you.

There is something called NUnitASP out there...haven't used it in years, but
back in the day it wasn't great (http://nunitasp.sourceforge.net/).

Karl
 
S

Samuel R. Neff

Well first, you can use the Web Application Project (free)
http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx to make 2005 web
projects behave like 2003 - which'll solve your assembly name issue. I use
it almost exclusively.

Karl

Web App Projects are not built into VS2005 with SP1.

Personally I wouldn't unit test the UI code. Extract all of the real
logical/data code to separate projects (which should be done anyways)
and unit test those dll's.

Sam
 
E

Eric

I'm with you on not using unit tests for the UI code. I would just be
trying to test the objects that hold the business logic. Currently I
have these objects in their own namespace, but still in the web
application project; however, it shouldn't be too difficult to move
them to their own class library.

Anyone else have a solution for unit testing in asp.net? Do most
people not use unit tests?
 
K

Karl Seguin

That's pretty much what I said...I just don't think a complete physical
separation is necessary (or even always possible). I want my HttpHandlers
as part of my web projects, and I can write them in such a way that they are
partially testable...

Karl
 
K

Karl Seguin

What about what I first said? About using the a Web Application Project
instead of a Website? They are two different projects in VS.NET...

The behaviour that you described is that of a "Website" project...if you use
a Web Application Project, you won't have Ap_Web variousgarbage.dll -
you'll have a properly (and predictably) named dll.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top