views:

164

answers:

4

I'm trying to test a class (a controller) that doesn't need to run inside the asp.net environment.

But when I run the test, cassini starts.

How can I avoid the cassini load?

Thanks

A: 

Your controller does need the asp.net environment, it is the handler for your requests. You can set your IDE to use IIS instead. Click on the properties page of your project and on the web tab you will see a Use IIS radio button which will let you set up a virtual directory. Then no more cassini.

If you have used the create unit tests feature in Visual Studio then it will have made a test like this

[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\working\\MDTest\\MvcApplication1", "/")]
[UrlToTest("http://localhost:1169/")]
public void AccountControllerConstructorTest()
{
   //Implementation
}

The UrlToTest attribute is what is causing cassini to start. As I stated above, your controller does need the asp.net environment because it is an http handler, so it needs to be invoked using http in order to test it. If you just don't like cassini (fair enough) then you are still going to need IIS to get it to work.

If you right click on your web project, then follow the instructions at the top of this post, the Create Unit Tests feature will produce this

[TestMethod()]
[HostType("ASP.NET")]
[UrlToTest("http://localhost/MvcApplication1")]
public void AccountControllerConstructorTest()...

Which runs without cassini :)

Mark Dickinson
I don't want to use IIS, I just need to test the class without web environment.
I'm not sure why this would cause Cassini to start. Is this a unit test, or an automated test? Maybe you could post some code for your test, and maybe also some of the target code. Also, if it is a unit test, is it nunit or microsoft?
Mark Dickinson
Just tried it out, please let me know if it doesn't help, or vote as answer if it does :)
Mark Dickinson
A: 

Cassini should only run if you debug or run your project (i.e. by pressing F5 or Ctrl-F5), not when you execute your unit tests. You can modify what happens when you press F5 by viewing the properties for you ASP.NET project and selecting the Web tab. You haven't specified how you execute your tests, but both the Visual Studio unit testing framework and frameworks like NUnit will run your tests in a separate process that is not Cassini. If you instead have say your own console application project to execute your tests you should make sure that you have set this project as the StartUp project. Then pressing F5 will execute your test console application and not Cassini.

Martin Liversage
When I try to run the test without debug (from VS), Cassini starts.
If you have an ASP.NET Web Application project and you have configured it (on the "Web" tab) to "Use Visual Studio Development Server" it will start Cassini when you run your project. It doesn't matter if you run the debug or the release version. You have to decide what to start instead of Cassini, perhaps a console application, or use a testing framework like the builtin or NUnit.
Martin Liversage
A: 

If you run your tests in debug mode cassini will start. If you run your tests without debug mode then it will not.

Shiraz Bhaiji
I don't now why, but it starts on both modes (with debug and without debug)
You may have marked multiple projects as startup project, and/or the run mode is marked as debug instead of active for the web project. It could also be a build event on one of the projects.
Shiraz Bhaiji
A: 

The problem was the code coverage. I have disabled it and now cassini doesn't start anymore (without debugging).