I have NUnit test project in my solution. I'd like to be able to run its tests on a set of different environments using a network of virtual machines and then aggregate result XMLs from each machine to my server.
I guess I would need to install NUnit to all my VMs in order to do it that way. But maybe I can avoid it somehow? Hypotetically I can change my test assembly's output type from class library to console app and call all my test methods (those ones with right NUnit attributes) using reflection manually from Main method and write XML output myself.
So I'd like to know if there are any testing framework that can make it for me. Ideally I would like it to create standalone executable that I will be able to run on a bare installed system, with no need to install some additional testing software. This executable will run all its tests and generate some test result output (it better be NUnit-compatible, but it's fine if it's not, I can handle some post processing).
Any ideas how I can achieve this?
Thanks in advance.
Related
I have a C# application built over .NET 4.6.1 (VS2017).
I am now building a test environment and would like to include user base tests.
The user provide a folder of files, each one is a seperate user test i need to run against.
I would like to create a TestMethod for each file to run against my application within VS2017.
Is there a way to automate such task? or the only way is to write a script to create the TestClass implementing a uniqueTestMethod for each file
You can make use of the xUnit tests using parameterised tests with InlineData. Article with examples
Is it possible to embed test code (based on one of the MSTEST, NUNIT, or XUNIT) inside a dotnet core console app?
Based on the tutorials like the one below, it seems there is the requirement that the test code has always to be a separate project than the actual project.
I understand some of the cons of embedding testing code in the actual project, but I really don’t want to turn many of the internal classes to public, or adding the InternalTo attribute everywhere, just to make them accessible to the test code.
https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest
I always create new project for Unit Tests, but you can have Unit Tests in your Console Application.
Just for demo purposes, I've added all the classes in one single file.
If you don't want your tests on production, you can surround your test classes with the #if DEBUG and #endif.
This way, it will compile on debug mode and be ignored on release mode.
Hope this helps.
You can also use NUnitLite to create an executable test program, which runs your tests. Link to both the nunit framework and the corresponding version of nunitlite and write a Main following these instructions: https://github.com/nunit/nunit/blob/master/src/NUnitFramework/nunitlite/AutoRun.cs#L34
We are developing and maintaining a legacy winforms application. The application uses a domain model which ist quite separate from the GUI layer, but because of many dependecies, it is hard to unit test. At least we have a build and an installation script which we can use to automatically build and deploy the application.
Now if we could only have some automated system tests...
We came up with the following idea:
First, we could write our tests in script files like this:
public class Test
{
public void TestSaveACustomer()
{
var c = new Customer();
c.Name="Miller";
Mapper.Save(c);
Assert.IsTrue(c.CustomerId >0);
}
}
Then, after building and deploying the application, we could run the scripts with a script runner that is baked into our application binary. We imagine we could use the following commandline
myapp.exe /runTest c:\myScript.cs
We could start to build our own Testing framework, wouldn't that be cool? ... er... no. It would be much less work if we could use an existing testing framework like nUnit, xUnit or MSTest from our application .
I guess I need to
Start a UnitTestRunner
Compile the Script
tell the runner to run the tests in the compiled script assembly.
I have no idea where to start, because I have only used UnitTests from VisualStudio.
Would that be possible with any existing testing framework? Which are the main classes I would use?
Here a existing answer how to run NUnit tests by yourself.
Question is, what does you prevent from running the tests regularly?
To get to run myApp.exe c:\test\test.cs you would also need to compile the test, then run it. You still need to compile it against your app?
Can you debug your application from let's say Visual Studio? Right? So, you could add a 'sub project', which points to the main project for the dependencies and your code. Then you add your tests there, using NUnit regularly.
Or what does prevent that?
I have a test suite, comprised of both unit tests and integration tests, in a project using C# on .NET 4.0 with Visual Studio 2010. The test suite uses MSTest. When I run all tests in solution (either by hitting the button in the testing toolbar or using the Ctrl-R A shortcut chord) all of the tests, integration and unit, pass successfully.
When I either attempt to run the same tests from the command line with mstest (explicitly using the only .testsettings file present) or attempt to run them from the Test List Editor or using the .vsmdi file the integration tests fail.
The integration tests test the UI and so have dependencies on deployment items and such, whereas the unit tests do not. However, I cannot seem to pin down what is actually different between these two methods of running the tests.
When I inspect the appropriate Out directories from the test run, not all of the files are present.
What would cause some of the files that deploy correctly in one situation from Visual Studio to not deploy correctly in another?
The static content started being copied shortly after I wrote the comments above. The other major issue I ran into was that the integration test project referenced libraries that were dependencies of the system-under-test (with copy-local set to true) in order to ensure that the DLLs would be present when they were needed. For some reason, these stubbornly refused to copy when the tests were run through Test List or mstest.
What I eventually did to work around it was include [DeploymentItem] attributes for the DLLs that I needed. This got things working no matter how the tests were run. What I am still unclear on, that may have answered the underlying solution, or provided a better solution, is how Test View/mstest differ from the regular test runner (assuming that the correct .settings file was passed to mstest.). I'm putting these notes/workarounds in an answer, but I'll leave the question open in case anyone can address the underlying cause for how the different test execution paths differ.
I would like to run automated Silverlight unit tests from a Hudson build server. It seems there are two options:
Use Statlight, although it seems to be designed for TeamCity rather than Hudson, so it would involve a bit of hacking to get it to work.
Use NUnit Silverlight tests.
Can anyone recomend either of these options? Or is there a better alternative?
You can try using Lighthouse Silverlight Unit Test Runner, it works with every Build Server including Hudson, TeamCity and CCNet because it by default produces NUnit compatible xml results file:
http://lighthouse.codeplex.com/
In our company we are using NUnit with Hudson for automatized unit testing. It is simple to setup and execute.
Just download and unzip latest nunit somewhere on Hudson host.
Add Windows batch command as last buildstep with content like:
C:\NUnit\bin\net-2.0\nunit-console.exe "%WORKSPACE%\src\Test\AllTests.nunit" /config=Release /xml="%WORKSPACE%\src\Test\TestResults.xml"
This will execute tests as defined in "AllTests.nunit" file. It is possible tu point just to one assembly (.dll).
To populate test results within Hudson Job page, you would need to install Hudson NUnit plugin. Its possible directly from Hudson plugin management.
After instalation there will be new Post build action: Publish NUnit test result report.
If you check it, you've got line to enter path to test result report. Corresponding path for example above is:
src/Test/TestResults.xml
Hope it helps you to decide ;-)