1

I have several class files in App_Code in an ASP.net website running in Microsoft Visual Studio 2005 Professional.

In liu of using a full unit test suite I just want to somehow compile those project-wide classses into an .EXE so that I can nightly run unit tests on them.

I do know how to create a separate C# library project consisting of those files and how to include them into my website--but that is not desirable--I don't want to give up the ability to make on-the-fly code changes of those library classes when running the website in the debugger. As far as I know .Net debugger isn't powerful enough to modify code in included libraries with instant auto re-compilation on page re-load.

So, I want my cake and eat it, too:

  1. Command-line unit testing of website class files in App_Code directory
  2. Being able to modify those class files w/o stopping/re-starting the web debugger.

Is it possible to have both?

2 Answers 2

1

You should put the code in an altogether separate class library/assembly, then reference it from your web project and the command-line utility. As far as I know, it makes no difference where you modify your code, when stopped in the debugger. Never had problems myself.

Hope that helps.

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

6 Comments

I just tried it and I get this error message: "This source file has changed. It no longer matches the version of the file used to build the application being debugged." This prohibits the edit and continue paradigm.
+1: simple and it works. And moving the code into a separate assembly has the benefit that it encourages devs to write testable classes which don't depend on the current HttpContext.
I am very surprised - are you sure you have the project in the same solution? If it's a separate solution/instance of Visual Studio you might get into trouble with it..
Ah... I had them in different solutions. I created a NEW solution with both the desired class library and website and when I attempt to edit the code in the library I now get a different error: "Changes are not allowed when the debugger has been attached to an already running process or the code being debugged is optimized." I checked MyLibary/Build/Configuration: Active(Debug)/General/[] Optimize Code is NOT checked... still confused!
It's more likely being specific about the fact that it was attached to the process after it had been run; are you using Debug->Start with debugging, or attaching to the web server ?
|
1

Your project is under source control, right? Right? In that case, you can use your source control system to include a link to your asp.net project's app_code folder as part of a separate unit testing project. The exact linking mechanism varies by source control platform, but done right it means there's exactly one instance of your App_Code folder in source control that's visible from two different projects. This way, everything stays up to date.

This has the advantage of allowing you to keep easy, uncompiled code right there just like you always have, but still making the code available for testing.

1 Comment

This solution does have a minor setback, when refactoring with a tool like ReShaper, it will miss references in the test project. This could lead to failing tests and the test project not building. Not a huge problem but something to be considered.

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.