How do I automate unit tests for a console application in TeamCity? - nant

I've written a console application that has a number of unit tests and I'm wanting to include it in my nant build script so that it will be run on our TeamCity CIS.
Unfortunately I'm not quite sure how to do that. The nant script has examples of current projects that have been added...they they all have to supply the assemblies that need to be tested. ie MyProject.dll But my console app doesn't have anything like that since it compiles into MyProject.exe
There must be a way to automate these tests since I'm able to run the unit tests from within Visual Studio without issue.
Does anyone know if and how this is possible?

The answer to this question is that you add the name of the executable in the same place you add the list of DLL assemblies. The set of unit tests is compiled into the executable instead of into a separate dll file.
Gishu is the one who should take credit for this answer...since he answered me via a comment...however, I'm wanting to mark this question as answered so I'm writing up the answer so others can benefit from the solution.
Gishu, if you ever come back to this question, please feel free to write up your comment as an answer and I'll change the accepted answer to yours.

What Test framework do you use for those tests? You've mentioned Visual Studio, I may guess it is mstest. TeamCity added support for MSTest starting from 4.0 for sln2008 build runner.
Could you please have a look to a full list of supported .NET unit test frameworks at
http://www.jetbrains.net/confluence/display/TCD4/.NET+Testing+Frameworks+Support
Any way, have a look to custom unit tests integration manual pages at
http://www.jetbrains.net/confluence/display/TCD4/Build+Script+Interaction+with+TeamCity

I've just noticed xUnit tag. xUnit supports TeamCity. Please refer to
http://www.codeplex.com/xunit/WorkItem/View.aspx?WorkItemId=4278
for more details.

Related

No possbile to set "--workers" via NUnit Engine API

Nunit command line has arg --worker to set LevelOfParallelism
We are running the test programmatically via NUnit Engine (https://docs.nunit.org/articles/nunit-engine/Getting-Started.html)
And I could not find a way to set "worker" in Test Engine or Test Runner
Maybe someone knows how to do this?
I've Google and debugged Test runner - could not find anything
UPDATE:
package = new TestPackage(arguments.Value.testDllPath); package.AddSetting(FrameworkPackageSettings.NumberOfTestWorkers, 8);
Short answer...
Add a setting to the TestPackage you use to get a runner from the engine named "NumberOfTestWorkers" with the value set to the number of workers you want the framework to use.
Details...
This is not actually part of the engine but part of the NUnit framework. The engine is generally framework-agnostic, that is, it doesn't assume you are running tests with the NUnit framework. However, it passes through any settings on the package, which it doesn't understand. It's up to the test framework in use to interpret them.
That's why you can't find the details in the engine documentation, although it could probably be improved by adding a paragraph like the above somewhere. :-)
Bear in mind that writing your own test runner using the engine directly is a somewhat advanced activity. I think the engine docs give you a lot of info about how to get started but you will also need to examine source code of existing open-source runners. For example, looking at the console runner itself, you could have seen this code (reformatted to fit):
if (options.NumberOfTestWorkersSpecified)
package.AddSetting(
FrameworkPackageSettings.NumberOfTestWorkers,
options.NumberOfTestWorkers);
The class FrameworkPackageSettings is part of the runner and includes settings used by the NUnit3 framework and exposed by the runner.
Good luck!

How to fix "Either assembly contains no tests or proper test driver has not been found."

I am getting error as mentioned Either assembly contains no tests or proper test driver has not been found.
When i enter "nunit3-console.exe project.dll".
I tried few solutions but it doesn't help me.
Assumming you have not found a new bug in the NUnit engine, then one of the two things in the message is probably true...
You are running an assembly that has no tests
You are running an assembly with tests for which there is no driver installed, IOW tests that the engine does not know how to run.
These two things are combined in one message because it's really all one thing to the engine, which is basically telling you "I can't find anything that looks like a test to me."
Most likely, you do not have any NUnit3 tests, because knowledge of those is built into the engine itself. So, I would guess you are either running NUnit V2 tests or tests from some foreign framework, like xunit or microsoft test.
For more of an answer, please tell us what kind of tests you are running. What testing framework (and version) do your tests reference? If you are running NUnit V2 tests, do you have the V2 Framework Driver extension installed?
So... maybe there is a bug in the NUnit engine.
I had this exact same error message on my build server. At the same time the tests were running fine in Visual Studio (2015 with Resharper).
This happened when I started converting existing xunit to nunit tests in an assembly. As soon as I removed the last xunit test, the error went away.
Try to comment out everything except NUnit tests to see if this fixes the problem for you.

Can MSBuild binaries be used on their own?

I've been using NAnt for sometime and although it works pretty well most of the time, some functionality is so limited you find yourself doing a page worth of work instead of couple of lines.
My biggest problem is returning results from exec task.. you HAVE to output to file then read the file then in my case substring what you read.
Multiply that by 8 different queries and you have lots of unnecessary work.
Anyway I would like to switch MSBuild which has much better support in this case.
But the problem is that I am using CI + Nant to deploy on staging and sometimes production and Nant is just a directory with files that you copy.
But As far as I know MSBuild must be installed and registered.
Is there such a thing as a standalone MSBuild download?
Thanks
I don't have time today to write up a rough history for MSBuild (I already covered ASP.NET on IIS and C# compilers), but I would tell you that MSBuild is not only standalone today, but open source at GitHub,
https://github.com/microsoft/msbuild
You can download the installers from Microsoft Downloads, or you can compile your own.
Reference: Rough History of MSBuild

Does the XML Report Processing work for NUnit3?

I'm currently moving one of our projects to DNX (.NET Core now) and I was forced to update to nunit3. Because of other considerations, we run compile the test project as a console app with its own entry point, basically self-hosting the NUnit runner.
I now need to report the results to TeamCity via the XML Reporter, which doesn't seem to parse Nunit3 TestResults.xml files.
Any advice on how to work around this?
The NUnit 3 console has the option to produce results formatted in the NUnit 2 style.
Use the option:
--result=[filename];format=nunit2
Docs: https://github.com/nunit/nunit/wiki/Console-Command-Line
To add to the answer above:
NUnitLite inherits the --result CLI parameter which seems to do the trick.
Another option, which I went for in the end is using the --teamcity CLI parameter:
dotnetbuild --project:<path to project directory> -- --teamcity
which will integrate with TC's service messages. This will also do real-time updates.

NUnit vs MSTest - a fickle TDD novice's experiences with both of them

There are a ton of questions here on SO regarding NUnit vs. MSTest, and I have read quite a few of them. I think my question here is slightly different enough to post separately.
When I started to use C#, I never even considered looking at MSTest because I was so used to not having it available when I was using C++ previously. I basically forgot all about it. :) So I started with NUnit, and loved it. Tests were very easy to set up, and testing wasn't too painful -- just launch the IDE and run the tests!
As many here have pointed out, NUnit has frequent updates, while MSTest is only updated as often as the IDE. That's not necessarily a problem if you don't need to be on the bleeding edge of TDD (which I'm not), but the problem I was having with frequent updates is keeping all of the systems up-to-date. I use about four or five different PCs daily, and while updating all of them isn't a huge deal, I was hoping for a way to make my code compile properly on systems with an older version of NUnit. Since my project referenced the NUnit install folder, when I upgraded the framework, any computers with the older framework installed would no longer be able to compile my project. I tried to combat the problem by created a common folder in SVN that had just the NUnit DLLs, but even then it would somehow complain about the version number of the binary. Is there a way to get around this issue? This is what made me stop using the first time.
Then one day I remembered MSTest, and decided to give it a try. I loved that it was integrated into the IDE. CTRL-R,CTRL-A, all tests run. How simple! But then I saw that the types of tests available in MSTest were pretty limited. I didn't know how many I'd actually really need, but I figured I should go back to NUnit, and I did.
About now I was starting to have to debug unit tests, and the only way I could figure out how to do it in NUnit was to set NUnit as the startup application, then set breakpoints in my tests. Then in the NUnit GUI, I would run the tests to hit the breakpoints. This was a complete PITA. I then looked at the MSTest GUI again, and saw that I could just click Debug there and it would execute my tests! WOW! Now that was the killer feature that swayed me back in favor of MSTest.
Right now, I'm back using MSTest. Unfortunately, today I started to think about daily builds and did some searching on Tinderbox, which is the only tool I had heard of before for this sort of thing. This then opened up my eyes to other tools like buildbot and TFS. So the problem here is that I think MSTest is guaranteed to lock me into TFS for automated daily builds, or continuous integration, or whatever the buzzword is. My company can't afford to get locked into MS-only solutions (other than VS), so I want to examine other choices.
I'm perfectly fine to go back to NUnit. I'm not thrilled about rewriting 100+ unit tests, but that's the way it goes. However, I'd really love for someone to explain how to squash those two issues of mine, which in summary are:
how do I setup NUnit and my project so that I don't have to keep upgrading it on every system to make my project build?
how do I get easier debugging of unit tests? My approach was a pain because I'd have to keep switching between NUnit and the default app to test / run my application. I saw a post here on SO that mentioned NUnitIt on codeplex, but I haven't any experience with it.
UPDATE -- I'm comparing stuff in my development VM, and so far, NUnitit is quite nice. It's easy to install (one click), and I just point it to whatever NUnit binaries are in my SVN externals folder. Not bad! I also went into VS -> Tools -> Options -> Keyboard and changed my mapping for CTRL-R,CTRL-A to map to NUnitit.Connect.DebugGUI. Not perfect since I haven't figured out how to make NUnit automatically run the tests when it's opened, but it's pretty good. And debugging works as it should now!
UPDATE #2 -- I installed TestDriven.Net and gave it a quick run through. Overall, I like it a lot better than NUnitit, but at the moment, NUnitit wins because it's free, and since it also works with NUnit, it will allow me to "upgrade" to TestDriven.Net when the time comes. The thing I like most about TestDriven.Net is that when I double click on the failed test, it takes me right to the line in the test that had failed, while NUnit + NUnitit doesn't seem to be capable of this. Has anyone been able to make this link between the NUnit GUI and the VS IDE happen?
Many projects I've worked on have included a copy of the specific version of NUnit (or xUnit.net, whatever) in a "lib" or "extrernal" or "libraries" folder in their source control, and reference that location for building all of their tests. This greatly reduces the "upgrade everyone" headache, since you really don't need to install NUnit or xUnit.net to use it.
This approach will still let you use something like TestDriven.Net to execute the tests, run the tests in a debugger, etc.
For easier debugging (and running, too) of unit tests I recommend checking out TestDriven.Net. The "Test With > Debugger" feature is so handy. The personal version is free.
Have you played with the "Specific Version" property on the NUnit.framework reference? We keep ours set to true so that the tests that are coded for a given nunit version require that specific version to execute.
I'm not sure how it will handle, for example, if you had 2.5 on your machine but another machine only had 2.4 - would .NET bind to the 2.4 version happily or will it only bind from earlier versions to later versions of an assembly (e.g. compiled against 2.4, but 2.5 availale at runtime?)