Debugging API and unit test from same solution - unit-testing

I have a WebAPI project and a test project for API in same solution as shown below.
The code of controller is shown below. As you notice I have a breakpoint setup on the Get method
The API is working fine such as via postman or browser as shown below.
One of the unit test is just calling the same Get API via HttpClient class.
Problem is I want to setup both projects (API and test) so that I can debug code from a single solution. For that I have setup both of these projects as start up
If I hit F5 key to start debugging, I get following warning which makes sense
In order to debug the unit test and choose “Debug Tests” option as shown below
With that I get following exception that A connection with the server could not be established.
In summary
1. The API is working fine as I can test it via PostMan
2. If I move the unit test project in a separate solution, then I can debug API fine. The breakpoint get hit and everything is fine
My question is how to debug this when I have both projects in the same solution?

Related

How to unit test UWP App with Azure Mobile App?

Consider a Visual Studio 2017 solution with 3 projects:
UWPApp - Universal Windows App
UWPAppTest - Universal Windows App Test (NuGet package: Microsoft.Azure.Mobile.Client)
MobileApp - Azure Mobile App web service (NuGet package: Microsoft.Azure.Mobile.Server)
I'd like to create a unit test in my UWPAppTest project, that calls my web service, running locally in my MobleApp web service project.
This requires me to somehow configure Visual Studio to launch the MobileApp project (selecting "don't open a page"). And at the same time, click "Debug Selected Test" in my test explorer. Or, somehow automatically launch the MobileApp in debug mode, when I debug a unit test.
This doesn't look like a supported scenario, and if not, what would be the next best workaround to be able to run a UWP test project, with tests calling a local web service?
Thanks
-John
This is something that Azure Mobile Apps has had to deal with as well. We use end-to-end test scenarios with a mobile backend hosted in the cloud. The test run will clear the contents of the database prior to each run, thus ensuring the appropriate unit testing. The biggest thing here is dealing with state.
In a local debug version, you will want to set the URI passed into the MobileServicesClient to your localhost, but things should not be any different. Just ensure you are fixing the starting point and ending point of your database for each test.

How do you debug unit tests?

I'm running some nunit tests in xamarin studio. They run fine but there does not seem to be an option for running them in debug mode. I've even looked through the keybindings in xamarin to see if it's an option (which is hidden from the menus but can be activated by a custom shortcut)... no luck.
If I want to debug a test, I have to copy and paste the code from the test method into a console application which is hooked up to the same references as my test project.
Any ideas?

How to Mock MVC4 application when UI testing with Watin?

What Im trying to achieve is to write UI tests for my MVC4 web application using Watin. Now I create a Browser object and open on URL localhost:xxxxx.
Problem is that the code running on localhost:xxxx using IIS Express is using production code which I dont want to be doing during test. In test I want for instance my IAuth and IDataProvider implementations to behave differently.
How do you UI test on a mocked instance of your application?
Ideas? :)
Solution was to make a bat file which runs a msbuild command which deploy to my local IIS. This works like a charm.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe C:\Source\...\ProjectName.csproj /p:DeployOnBuild=true /p:PublishProfile="UnitTest" /p:Platform="Any CPU" /p:OutputPath="C:\inetpub\web" /p:VisualStudioVersion=11.0

Visual Studio 2012 Coded UI Testing of Web Application - Code coverage

I have a web application. I am using VS 2012 Coded UI for testing the web application. I have recorded the test and running it, and it works fine. But the code coverage window gives code coverage of the test project only, it doesnt give code coverage of the website project and other dll project which is referred in the web project.
I have added the testsetting file in the solution and selected the same.
Any clue?
Couple of things to verify
a) Have you added all these assemblies into the code coverage configuration's list of assemblies via the testsettings?
b) Is your deployment of the web app happening as a part of your test run? If so then you should ideally have the "instrument in place" option selected

Dojo DOH, unit tests with robot actions wont run

When try to run dijit tests from 1.7 version, popup window shows up and test will not progress any further.
Popup says:
DOH has detected that the current web page is attempting to access DOH, but belongs to a different domain than the one you agreed to let DOH automate. If you did not intend to start a new DOH test by visiting this Web page, press Cancel now and leave the Web page
Clicking OK or Cancel doesn't do anything.
Whats going on a how to fix this?
Browser is Firefox 9, java is working (at least test page say so).
It's slightly hard to tell what the problem is, as you've not said whether you're running this from a local filesystem or under a web server, or which URL you're using.
I've had various problems trying to get DOH Robot running from the local filesystem, but good success running them under a web server.
Try it under a web server (any type will do), and try visiting the URL
http://server:port/ROOTDIR/util/doh/runner.html?testModule=dijit.tests.form.module
(where http://server:port/ROOTDIR/ points to the top of your Dojo SDK directory)
That works fine for me with Dojo SDK 1.7.2; sometimes I then get the same prompt you get, but OK enables the test to continue happily.
If that doesn't work, see if you can run a test page directly without the DOH browser runner wrapped around it, e.g.
http://server:port/ROOTDIR/dijit/tests/form/robot/Button_mouse.html
That might prove easier to diagnose.