Starting asmx service when running unit tests - visual-studio-2010

We have a VS 2010 Solution with many projects.
One of the projects contains asmx services.
We have a problem that our tests fail if the services are not running.
What is the best way to make sure that the services are started when the tests run? We need to get this to work both on the developers machine and on the build server, where we use TFS.

Found a solution, it was to use WebDev.WebServer40.exe

Related

Launching integration test (MSTest) after starting the API without using two instances of Visual Studio

I have a .NET WebApi and an MSTest Project that contains the integration tests to call the API via HttpClient.
Because I did not find a way how to let the MSTests run while the API is started, I start Visual Studio 2022 two times.
One instance with the launched API and then another instance where I can run the tests.
But this is not a nice solution, because pretty often both projects are trying to "build" in the same location.
This leads to error messages looking like this:
There must be a better way, but defining multiple startup projects also does not work.
The best would be to start my Integration Tests a short while automatically after launching the main API Project.
How would you do this?

Test Project in Visual Studio 2010 for a Windows Service Project

I am working now in a Windows Service Project and I am having a lot of headaches trying to debug the service, I found a lot of article on how to debug a service but none of them worked for me :(
How to: Debug Windows Service Applications
There is no way after attach the process to enter in my breakpoints (set breakpoints everywhere)
Then I found another creating a windows form inside the project but that Solution is kind of dirty (but a solution).Testing a Windows Service From Within Visual Studio
So the real question is, is there any possible way to create a test project to test the service? (I don't have experience with testing, but I know is a good practice)
Do you want to debug the service or code that service runs?
In the past I would create one project for a service, one project for a library that contains the logic, and one project for a console app that would be used to test and debug the logic locally. That setup covered most of the debugging needs.
Hope this helps!

Building on Team Foundation Services and Testing in Azure?

I'd like to run some integration tests in Azure. I can't run these in TFServices because they require a database. I'm wondering if it would be possible to push my project up to TFS, have TFS build the solution and push it to Azure, and then have Azure run some tests against a test database before committing it to production. Any failures along the pipeline populate back to visual studio. Is this even remotely possible?
if it would be possible to push my project up to TFS, have TFS build
the solution and push it to Azure
Yes, this is possible.
and then have Azure run some tests against a test database before
committing it to production
Well, this is not possible.
Any failures along the pipeline populate back to visual studio
And this is in a dream world. The only viable resolution is to have work items created out from test fails. But populate back to Visual Studio is a dream.
Going back to have Azure run some tests against a test database before committing to production.
What exactly is the issue you face when you want to run integration tests from TF Services? is this just an SQL Azure Firewall issue or something else? Have you even tried it? What was the result? If it is just a Firewall issue you most probably can mitigate by using some custom code in test initialization phase - like disabling firewall for the SQL Azure server, then enabling it again on test tear down phase.

Visual Studio: Unit Testing a web project in the same solution

I have a solution with a WebAPI project and a VS Test project.
My tests make calls to the API using RestSharp via a Url rather than instantiating the controller itself and injecting things (context etc).
My question, is there a way to tell the test project to launch the web project via IIS Express when a test run begins? Currently I just run two instances of VS, one with the web projected with debugging started and the other running the test package
If you are trying to debug both the test and the service, consider doing this
Launch to debug your Web service in Visual Studio.
Click Debug -> Detach All. IIS Express will keep running.
Set a break point and start Debuging your Unit Test.
(Skip this if you don't need to debug the web service) Click Debug -> Attach to Process. Find iisexpress.exe and attach.
However, you lose Edit and Continue on your web service which was detached.
I wouldn't recommend using the network to unit test Web API. You open yourself up to potential flakiness in the test and you end up testing a whole lot more than the service itself.
But if you really must do so, maybe to test that your client can exchange information with the API, then I'd suggest you look into self-hosting the service:
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/self-host-a-web-api
Self-hosting lets you start up a server for Web API with just a few lines of code and you could have your tests start up this server in the right places. In most cases, this should behave the same as having your service hosted in IIS Express. But there are some important distinctions. For example, you won't be able to use some System.Web concepts you may be used to (like HttpContext.Current).
Update:
I've written a blog post about testing Web API services that might help -
https://learn.microsoft.com/en-us/archive/blogs/youssefm/writing-tests-for-an-asp-net-web-api-service
Hope that helps.
I know this is an old post but I was just faced with this issue. I can provide a more detailed response if / when anyone reads this.
In short.. I created a console app referencing the unit test assembly and via reflection and a simple menu system you can run any one of your tests.
I then set multiple startup projects to be the Web project and the console project.
I can then F5 and debug both the unit test and the Web project from within the same session. No attaching to a process of multiple solutions needed.
Running your web service or site in release non-debug by CTRL-F5 makes it run independent from Visual Studio and you are free to run your Tests from inside VS
I know that this is late but I use this solution:
Start two instances of Visual Studios. Start debugging the API in one VS and then debug the test in another.

My Visual Studio 2010 IDE is often hung when run unit tests, how to get rid of it?

I often have to restart my IDE when trying to run a test set from within Visual Studio 2010 since it keeps being hung/not-responding very often.
Do you have the same problem? If you do, do you have a work-around for that? Please share.
I'll share my setup with you. It won't solve your problem but might give you some ideas to improve your unit tests.
First, my unit tests do not connect to the database or reference cookies / session. In those scenarios, I use Dependency Injection (with Castle Windsor) to pass fake repositories to the unit tests. If your unit tests are hitting anything external (Web services, SQL, IIS) that might be a good place to look.
I use NUnit / Moq for the unit tests themselves. I had been using the NUnit client to run the unit tests but then I stumbled on a tool called Gallio that allows me to run (and debug) my unit tests from within Visual Studio.
I'm not sure if Gallio is compatible with your unit tests or not, but it might be beneficial to debug the unit tests to see exactly where they are hanging up.
EDIT: Thought I'd add that I'm using Visual Studio 2010 Premium and I have about 110 tests so far that complete in a few seconds. The tests hit ASP.NET MVC controller actions.

Resources