This seems to be a weird issue, I had solution with a WCF Service and Unit Test Project.
In Unit test, I had some testcases which will step into WCF service. When I start the service, and go into Test-case (Test explorer) all test-cases are disabled, and in Test => all Debug / RunAll tests all options are disabled. So I am not able to debug testcases when WCF Service is running this is the issue. I am using VS2013 Ultimate with Update3 installed.
I am rightclicking on WCF Service debug start new instance, then go into Test-case (Test-explorer) when I right click on test-case all options are disabled and so is in Test menu.
Related
I am getting into Selenium WebDriver to write black box integration tests. I'm using MSTest (for now) as a test runner. There's a point where I want to call a WCF service to support the work. I get an error:
Could not find default endpoint element that references contract 'Abc.AbcService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
I realize that calling external services has no business inside a unit test, so I want to emphasize that I'm only using MSTest as a convenient temporary home for automated ui tests, which simulate real life situations of someone using the entire application, front-to-back, using a website driver in tandem with web services.
I guess the problem has to do with finding the .config file when the application is the test runner. Or maybe it is a general problem of having a config file for code in a dll that is hosted in process that you don't control.
If you are calling the WCF service from your test project, you can just add a app.config file with the service configuration in you test project. The configuration will be used to configure the services when called (the app.config file will be deployed with your test dll).
We have a CI setup using bamboo where one job was to run our automation, it checks out our Automation Solution from a repository, and run it using NUnit runner where it contains tests using selenium webdriver and some unit tests. It runs unit tests(not using webdriver commands) just fine, but not the webdriver tests.
We are sure that the solution is being checkout correctly because we can run the test using the command line referencing the created local repository, including tests that uses webdriver using the command below:
C:\pathToNUnitConsole\nunit-console C:\pathToCreatedLocalRepositoryInTheServer\NUnitTest.dll -include=FirefoxBrowserTest
We can see that the bamboo job never launched a browser, and we are getting test failure for not seeing browser elements. Also, we are getting error as we see in the logs:
10-Apr-2015 13:19:49 http://10.215.12.28:15871/cgi-bin/blockpage.cgi?ws-session=587410860
10-Apr-2015 13:20:42 JavaScript error: resource://gre/modules/CertUtils.jsm, line 168: NS_ERROR_ABORT: Certificate issuer is not built-in.
I don't know if this is your problem, but it sounds very similar to an issue I had trying to get NUnit runner to run tests built in SpecsFor.MVC, which is a wrapper that deals with instantiating an IIS Express instance, deploying a target web application to known location, then using Selenium/Chrome Driver to run the tests against the web app.
The problem I had was trying to run the Bamboo remote agent as a windows service. The Local Service account was not able to access the interactive desktop. Also, changing the service to run as a specific user account still failed, as the service was not allowed access to the user's isolated Session0.
I could login as that test user and run the test from the command line no trouble, but I couldn't get it to run when initiated by the remote agent windows service.
I eventually fixed it by using AlwaysUp (not a plug. I'm sure other similar solutions are available). This allowed me to set the machine running the tests to always log in as the test user on startup, would automatically restart the bamboo remote agent if it was closed for some reason and most importantly, to give the service access to the user's isolated session0.
Hope that might give you a few clues...
I created a WCF Service Application project in VS 2012. Implmenented the service.
here is what it looks like:
Now I have a fundamental issue to deal with. I created a new Test project to create more TDD and also some TAD tests. The TAD (Tests after Implementation) tests will test the service implementation while my TDD test will test reliant on mocking my WCF Servcie Interface.
But now going back to my TAD tests which need to test using an implementation of the service. I take that is I'm adding a service reference and using the clientProxy in my unit tests for TAD.
So I add a service reference to a new C# Project. I then continue to create some tests such as:
[TestMethod]
public void Get_CalledViaClientProxy_ReturnsNonNullList()
{
var serviceClient = new CarsClient();
// Act
Cars[] events = serviceClient.Get();
// Assert
Assert.IsNotNull(events);
}
When I run this it fails because the actual service is not running. So what I've done is go back to the actual Service WCF project, right-click the service (.svc) and choose to open it in the browser which will also start the service under IIS Express. Then my tests run fine.
So from that, how do I make this more automated. If another dev downloads this code, those tests should run and the service should somehow be started. I tried to set my service project as the startup project but all that does is opens the browser to show me the file system for that project.
How do people run the service for testing other than in IIS? and make it so it just works for devs? If I can't get my service to run simply but pressing F5 somehow and still able to go back into my tests project to try and run unit tests then this is pointless.
When I simply try to set my "WCF Service Application" project to be the startup project, instead of just starting the service and sitting there with a console window, it opens a web page for the service. Do I have the wrong WCF project type? I noticed that I have a web tab because I've got a "Serviced Application" project, should I be using something else if I want to simply start up my project in VS and continue coding in other projects that utilize this running service?
At a previous company I was at, we all put a "-d" in the WCF service project which when you ran the project it would start the service and a console window would run and just sit there, then you knew the service was running while you continued on writing TAD unit tests against it
e.g.:
however again, my WCF project is a "WCF Application Service" so I don't have that exact debug tab in mine so not sure what to do and then how we were able to have this format of tabs in the WCF service at other places I've been. Maybe it's just a plain C# project, not a WCF project where we were putting the -d but then how was it starting the WCF service if that was the case? Not sure if it was a plain vanilla C# project that we put that -d in but I sure do not have this same tab format in my WCF Service Application project.
Update #2
Ok I just to see the diff, added a "WCF Service Library" project along side my "WCF Service Application" project. The tab now has that debug and now when I launch it it does start the service and the test client comes up because the VS template automatically has /client:"WcfTestClient.exe" in for the command line properties of the debug tab in the project properties.
Since this service is going to serve as a service API that will be used cross applications, maybe I shouldn't be using a "WCF Service Application" and should be using a "WCF Service Library" type of WCF project template.
Refer your wcf project from the same solution as your test project.
Right click solution -> set startup projects
choose multiple startup projects and change the action of your wcfservice from none to start or start without debugging. Play and test :)
Or start project without debugging, wcf service will be running and you can continue coding/building and testing.
EDIT:
Here is what you also could do;
Change your wcf project to wcf service library, make sure this project have the following config...
under debug:
Start action: Start project
Start options: command line arguments: /client:"WcfTestClient.exe"
under wcf options:
Check "start wcf service host when debugging another project in the same solution"
Under solution -> startup projects, make sure you have a single startup project.
This way you can debug your other projects in the solution, visual studio will ensure that your wcf service is started.
You can host your service in local IIS automatically by configuring project settings from Visual Studio. Then whenever you compile your WCF service, IIS hosted instance will be updated and ready to serve automatically.
Right click your WCF Service project -> Properties -> Web -> Use Local IIS Web Server and click Create Virtual Directory. Before, do not forget to turn on your IIS services feature on your machine if not.
Additionally, why dont you test your concrete service implementation only just by referencing it, you dont need to run a service and connect it to test your business.
Usually you put WCF service logic in some other project, let say "WCF Login Library" and you test functions on that. You don't need wcf service to test those method calls. You can then use only one method to test the connection with WCF (that's usually done manually by me).
Isn't that simpler approach?
I have a Visual Studio 2012 solution with a test project that has tests that call a class library project which calls a WCF service project (this is a simplified summary of the status, the actual solution is more complex).
From the Test Explorer if I click on 'Debug Selected Tests' the tests then pass but if I 'Run Selected Tests' then they fail as the service is not being hosted.
I want to check my code coverage but the code coverage 'runs' the tests which means the service does not get hosted and thus the tests fail and my code coverage is 0%.
How can I configure the testing process so that the service is hosted when I 'run' tests as well as when I 'debug' tests?
Addendum
After consideration I think that mocking the service will not accomplish the goal. The various components have already been tested in isolation using mocking but now need to be tested to see how they operate together.
They're not unittests as they have an external dependency (another example is a database call) - you are relying on the webservice being up for the test to pass. This isnt a guarantee.
I'd say use a mocking framework here - I use Rhino Mocks but there are plenty out there. That way you can bypass the reliance on the webservice by mocking it.
In addition - I'd look at refactoring the class library you're calling if you can, seperate out the calls etc so you can test parts in isolation.
I'm running Hudson for my automated builds and love it.
I'd now like to create automated Web browser tests using either WaTiN (preferred) or Selenium.
As my Hudson runs as a Windows service (under Tomcat), how can I configure this to run? Will I be forced to log in as a user on the Hudson box so my automated browser tests will find a browser? Or is there some other sorcery with an interactive session that I can conjure up?
If possible I'd like the Hudson box itself to run the tests.
After some research I've found that WaTin won't work so well as I'd need to configure Hudson to run in an interactive Java session.
Selenium Grid, however, is perfect - there's a Hudson plug-in that can control it, too.
So that's what we'll use.
I'd now like to create automated Web
browser tests ... my Hudson runs as a
Windows service ... Will I be forced
to log in as a user on the Hudson box
so my automated browser tests will
find a browser? Or is there some other
sorcery with an interactive session
that I can conjure up? If possible I'd
like the Hudson box itself to run the
tests.
A Windows service can indeed run a browser, even when logged in as the LocalSystem account. We have that exact setup, with Hudson installed as a Windows service, although deploying it to Tomcat and running that as a service should work equally well. We use Sahi for our automated testing, which runs our test suite in both IE and Firefox.
You didn't say what problem you had with Watin, but in case it's relevant, Sahi needs to set the browser's HTTP proxy to a special host and port. This works no problems with Firefox because Sahi configures its proxy via a profile specified on the Firefox command line. IE is a little tricker, because its proxy settings are in the Windows registry, and when running as the LocalSystem account, these come from a special place in the registry (not HKCU as for a logged-in user). See this SF answer for the details. If that was the problem you were having, you may yet be able to achieve your goal of running everything on the Hudson box.
Have you checked here? This shows the Selenium Grid plug-in to Hudson.