How to run NUnit tests after deploy on deployed project - asp.net-mvc

Is there any way to run Nunit tests on deployed project?
Like after project has been deployed I have to run tests against the project on a deployed environment (because part of functionality can be run only on deployed environment due to the special access policy)

Is there any way to run Nunit tests on deployed project?
Normally NUnit is used to write unit tests against separate small functionalities of your application. If you want to run tests against a deployed version of your application then we are talking about integration tests. There are many different tools that can be used to test your running application. One of them is Sikuli. Alternatively if you want to keep using a .NET unit testing platform but firing requests against a real web server you can checkout SpecFlow. But no matter which tool you decide to use, you should be ready to write integration tests which are very different in nature compared to your unit tests.

It is possible to run tests writen for Nunit against a deployed environment.
You need a way to configure your tests according to the environment to test.
The type of test: unit tests, integration tests, functional tests, system tests etc. is independent from the technology you use to run them. NUnit is a technology to execute tests and gather their results. It has probably been architectured thinking about unit tests, but you can even implement your system tests with it.

Related

F# + xUnit - what could possibly go wrong

I've just literally hit a brick wall trying to configure F# 4.5.0.0 under VS 15.8.1 to run xUnit tests. Here is the repo with the issue: https://github.com/kkkmail/fSharp-xUnit .
When I try to run all tests, VS comes back with this message: No test is available in C:\GitHub\fSharp-xUnit\DummyApp\DummyApp\bin\Debug\DummyApp.exe C:\GitHub\fSharp-xUnit\DummyApp\Tests\bin\Debug\Tests.dll C:\GitHub\fSharp-xUnit\DummyApp\DummyApp\DummyApp.fsproj C:\GitHub\fSharp-xUnit\DummyApp\Tests\Tests.fsproj. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Both the "DummyApp" and tests were created from scratch using VS and I cleared all temp files and all nuget caches prior to creating the solution as advised in various places on the web.
TL;DR Add xunit.runner.visualstudio to your test project.
For discovering tests Visual Studio relies on its test runner. This test runner can discover / run all tests for testing frameworks which implement the corresponding adaptor interfaces ITestDiscoverer and ITestExecutor. For xUnit, these interfaces are implemented in VsTestRunner which is published in xunit.runner.visualstudio.
See also the xUnit docs about running tests in VS

TFS build Fails when Test projects containing MSCRM Organization service Url as localhost

I have a VM where MS CRM is installed and can be access using http://localhost:5555/Orgname/main.aspx.
I have created Unit test cases in my VM by refering the Organization Url as
http://localhost:5555/XRMServices/2011/OrganizationService.svc?wsdl
When I build the test project it connects to CRM and executes the test methods without any error.
Where as when I do a check-in ,the build is getting failed due to the reference to url "localhost".
for Build we have a separate Build server.
Can any one let me know how to solve this.
Your tests are being executed on the build server and it looks like some of your tests are of the Integration kind and not of the Unit kind, as such it's looking for a configured CRM instance on that server (localhost resolves to the host itself for every machine), and can't find any. Which means you have a few options:
Install CRM on the build server, extend the build process to deploy CRM to the build server during build in order to run your tests. A build process like the one developed by Wael Hamze can be extremely helpful for such a solution.
Do not include a localhost address, but actually check in a location that points to a shared dev environment, the build server can connect to. This is not ideal, as the build may be dependent on specific data being present and concurrent builds may break due to strange interactions. If you configure the build agent to only run 1 concurrent builds, it may work.
Disable the tests that depend on an installed version of CRM. You could put a [TestCategory("Integration")] on these tests and then set a filter condition on the build to exclude this test category.
Or you could try to improve your tests by making them independent of your configured instance, using Fakes or any other mocking framework. There are several testing frameworks specifically made for CRM workflow activities and other parts specific to CRM.
You need to remove the Integration Test from the list of Unit Tests that are executed as part of the build. I recommend creating a new project called [projectundertest].IntegrationTests and adding all your integration tests there. Then configure the build to only execute UnitTests...
You build server is trying to execute all of the tests in your solution. Unfortunately you have an Integration Test masquerading as a Unit Test. When it is executed the test tried to access CRM and fails. This is correct behavior.

Include common tests in Erlang release

I have a project written in Erlang (and releases generated by rebar) and I want to do integration testing in an environment which is as close as possible to the deployment environment.
The project pulls in a few other Erlang applications as dependencies. One of these applications has common tests in test/. It is these tests I wish to run in the release.
Is there maybe a way to have the common tests included in a generated release, and somehow run them on the target instance?
I don't want to run these tests on the application in deps/, but on the actual release itself.
Thanks!
Leave the tests out of the release. Build the release, then start it from a CT run (test_server has a nice way to start slave nodes). Now you can call into the other node to execute test cases.
I find that this method is often easier to get working.

ASP.NET MSTest Runner to run unit test via browser

We are building a sitecore web application and unit test is based on MSTest. I had a look at link below which has asp.net nunit test runner:
http://www.codeflood.net/testrunner/
However, we don't want to use the nUnit framework for out of box MSTest suit. Could someone please help if there's any existing test runner or how easy it is to convert the nUnit Test runner to MSTest runner?
The reason we want to use the test runner is to run unit test with in HTTPContext.
According to this stackoverflow post the API used by MSTest is sealed and private which is not going to help you in exposing a test runner that mimics the NUnit TestSuiteBuilder functionality.
It could still be done via Reflection if you are determined enough but it might just be simpler to use the technical restrictions around MSTest to build a case to migrate your unit tests that require a Sitecore context to NUnit.

How to run selenium tests in Microsoft test manager

I have some automated tests written in nunit and selenium. How can I call the dll to execute from Microsoft test Manager. as I couldnt figure out how to run automated tests from MTM. is it possible.
MTM does allow to automate the test.
We can browse a test case in Visual Studio and attach the executable to the test case (Created in MTM). Later we have to link the build to the test plan as well for the execution of the automated test. Test code should be developed as a test project (CodedUI or Unit test) if not done so the test manager will not detect the method to be tested.
For MTM to run automated tests with Selenium you need to associate the test with a Test Case in MTM. Currently MTM only supports MS Tests so you would need to build a wrapper for each of your selenium tests.
Solution #1: I would build the wrapper with a T4 template that generated the required MS Test stubs that call my Selenium tests.
You would then need to have a Test Case in TFS with the MS Test 'automation' associated with it.
Solution #2: You can use the "tcm import" command line tool to generate and keep your Test Cases in sync with the automation.
Now that you have all of the bits configured you can go ahead and call the generated tests from MTM and you hit the issue that #richard mentioned.
Solution #3: You can configure an Environment in MTM where you are going to collect the data and automate the trigger of the test run. This can be done as part of the Build, or better as part of your binary Pipeline in Release Management (http://nakedalm.com/execute-tests-release-management-visual-studio-2013/)
While there are a lot of hoops to get all setup I have found this to be a fairly robust way to execute the automation. It would be a lot easier if MTM supported other test frameworks, but that is not the case just now.
MTM doesn't run automated tests. It's a tool designed for manual testers. The only automation it offers is the record/replay of actions that a tester has recorded.
If you want to automatically run Selenium tests then look at running NUnit as part of the build process, just make sure the build agent is running as an interactive processes not a service so that Selenium can access the desktop and run a browser.
Alternatively you could look at using a headless browser such as XBrowser or HTMLUnit (though you'll need to use the Selenium2 remote driver)

Resources