2

So I'm trying to get productive practicing TDD in a ASP.NET webpages project, and launching a server every time I want to run my tests, well it isn't quite fast. So I'm trying to find a way to do my testing without the use of the [HostType("ASP.NET")] attribute, but there is always some error. We're using App_GlobalResources folder for our resource files, and this is one of the problems; when removing the attributes, just keeping the [TestMethod] (using MStest), it can't find the resources. So I'm !NOTE assuming, that it's not able to find the resources assembly.

So, has anyone done this before? Any experiences?

And comments saying "why don't you just convert to MVC", well it's just to big an app and to little time. Maybe it'll happen in a couple of years, maybe more, maybe never.

3
  • I think you should investigate Selenium Commented Aug 10, 2012 at 8:54
  • 1
    Selenium is great for integration tests but heavyweight for unit tests and would be slower than OPs current situation Commented Aug 10, 2012 at 8:59
  • Must agree with @Daniel Elliott here. I'm just trying to get the logic tested, not the acutal usage of the app in the browser. I'm trying to get the same speed practicing TDD in webpages as one would get in an MVC app, if possible. Commented Aug 10, 2012 at 9:15

2 Answers 2

3

My experience testing ASP.NET Web apps has been painful (which looks like yours is too!) Resisting MVC Comment

My best advice would be take little steps each time you touch an area to make it more testable. For example, for any bits of code you can pull out to it's own assembly that you can reference do so.

First candidate would be you resource files. Then your tests could reference that satellite assembly without the "App_" hoops to jump through.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks! I'm trying to extract as much of the logic to a library project, wich is easily testable, and fast. And your saying I could move the App_GlobalResources folder to this project, and add a reference to it in the webpages project?
The actual resource files from the directory, yeah and reference the new project in the web app :)
I found using a model-view-presenter approach really useful with webforms. It vastly improves the testability of our apps without needing to start again with an MVC app. I've been able to implement it on a page by page basis as I need to fix things in the app.
Thanks @DanielElliott, I'm going to give that a go.
@SimonHalsey in what way would you say that it helped you? What did it make easier? Does it have to create a webserver to run the tests?
|
1

The approach I took involved creating a presenter class for each page. You create an interface that the page implements with methods & properties that the presenter needs to control the UI. All your logic goes in the presenter, along with a reference to the interface. the page references the presenter and passes itself in.

The benefits you get are the page now should only contain code to make the UI work. The presenter does most of the work. Because it can access the UI, via the interface it can control the UI. Because the access is via an interface, you can test the presenter using a mocked UI.

I found my pages were vastly simplified, with much greater differentiation between code to support the logic of the app & code to make the UI work. It also made it simpler to introduce service classes & IoC which is not always the easiest with webforms.

2 Comments

Interesting, going to have to look deeper into that. When you write your test, does it run without setting up a server ie. no [HostType] attr? Thanks for the help!
You can test the presenters without it, as they're just POCO's. If you want to test the webforms, then you obviously need to test them as you currently do. The advantage is of course you'd lowered the complexity & therefore the amount of code in the webform class that needs testing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.