Visual Studio plugin for automating nunit test creation? - unit-testing

You know how they say, "There's an app for that"? Well, is there a VS plugin for this ................. ?
I want to be able to right click on a method and select "Create unit test method ..." and have it generate an nunit stub in a particular place in my project tree. So for example. I have a TheNextBigThing library with an Idea class and a MakeMeRich() method. I want to have it, for example, create a unit test method in my Tests project in a sub-folder named TheNextBigThing, in a class named IdeaTests.
I know. I know. All the TDD advocates will tell me I'm doing it backward, but humor me. I have some code I want to retrofit with some tests, and I sometimes write methods before tests.
If it doesn't exist, any pointers on how to write it myself?

If you are running Visual Studio 2010 Professional or Premium you have the option to create a unit test with MSTest by right clicking on the method.
Also, I would suggest using Pex. Pex will create the unit test for you, in addition to all unit tests needed to achieve 100% code coverage of a particular method.

It wouldn't be too hard to get the addin started. Since you have VS already, simply create new project > VS Extensibility. :)
You'll most likey have to learn some codegen unless you utilize a templating language of some sort.
Me? I think it's a cool idea and I'd like to see it implemented. Start it up, share it on github (or similar) and watch it grow.

Related

How to exclude or include a group of tests under NUnit

I'm a new NUnit user, using NUnit 3.9 under Visual Studio Community 2017. I'm using it on a pet open source library project, and it's going well once I got the hang of it.
The library accesses a publicly available government website via a documented API. Most of my tests use local data, so that I have a stable bed to compare against, and so that I can test without going out to the website every time.
I would like to set it up so that normally, the tests that hit the server do not run. I run the tests over and over as I tweak the code, and just as a matter of courtesy, don't want to bang on the server. Also, I'd like to be able to test even when the remote system is down or when I don't have Internet access.
Is there any way to group or tag my tests so that normally only the ones using local data run, but that I can still, when necessary, run the ones that exercise the server access? Either specifying "run these" or "exclude these" would be fine.
I've grouped the tests into two different classes, UnitTestOffline.cs and UnitTestOnline.cs, and was hoping I could somehow run the tests on a class-by-class basis, but haven't found a way to do that.
You'll get better answers if you say specifically how you run your tests, since there are a number of ways to do it. Since you mention VS2017, I'm going to assume that you are using the NUnit 3 VS Adapter, but let us know if you are using some other approach.
In the VS adapter, use the dropdown to display your tests by class. Right click on the class for which you want to run tests and run them.
If you decide to categorize tests using the CategoryAttribute, you can display tests by "trait" in Visual Studio. As before, right click on the group you want to run tests for and run them.
If you get a lot of tests, you might want to put your unit tests in one assembly and your integration tests in another. In that case, display the tests by project, right click on the project you want and run them.
All of this can also be done using the nunit3-console command-line runner as well. To select by class or category, you use the --where option. To select by assembly, you merely enter the name of the assembly you want on the command-line.
Seems like you want to categorize your tests (unit test, integration tests...) and run only the unit tests... you could use [Category] for that.
In the nunit GUI you could /include /exclude category after that and run only the one you want.
And probably that the filtering of Visual Studio could work.
Try to see one of the solution suggested here as well

Smart Unit Tests standalone

I've been working with Smart Unit Tests (formerly Pex) for some time now. Pex had the ability to run as a standalone, command-line application which was really useful for several scenarios (e.g. extending the list of parameters of the Parameterized Unit Tests).
However, in the case of Smart Unit Tests (integrated in VS2015), I was not able to find a function to run it standalone (it only works with right clicking on the method to be analyzed). So, for example, when I want to extend the list of PUT parameters, I have to do it also in the method under test (which I really want to avoid) in order have it discovered by Smart Unit Tests.
So, my question is, that are there any possibilities to run Smart Unit Tests only from the generated PUT method like it was in Pex?
Please try the VS 2015 RC build. You should be able to 'Run Intellitest' directly from the PUT.
Yes, running an IntelliTest exploration is supported from both the code under test and from the generated PUT.
Please note that starting with the VS 2015 RC build "Smart Unit Tests" has been renamed to "IntelliTest".

How can I perform system or integration tests using visual studio 2012 without including them in run all tests?

I am working on a project in where I decided to use unit tests. This was new to me but after researching I feel pretty confident I am doing it correctly creating mock objects and testing that the correct methods are called. This is working great but now I would like to actually run some tests that use the actual database and external components. How should I go about testing the actual execution of code? I do not want these tests to run when I run all tests. Is there a way to accomplish this using built in testing in vs2012?
Not that I'm aware of.
What you could do is create a separate project for your integration tests and then in the test explorer, separate your tests by class. Or some other logical seperation.
the current implementation that exists seems to specifically have unit testing mainly in mind, but that should change with 2013 and a stronger push towards TDD and Agile development.
Have a look here :http://msdn.microsoft.com/en-us/library/ms243147(v=vs.80).aspx
Scroll down to "Attributes for Identifying and Sorting Tests". There might be something there that's useful that you can use.

Unit Testing with Boost and Eclipse

I can't work out how to get unit testing to work with Boost and Eclipse.
I get lots of different errors depending on where I put the source files.
Where are the tests supposed to go? (ie should I create a test folder in root, in src, no folder at all or what)
Do I need to specify something somewhere if I don't intend to have a main(), and just lots of tests?
I'm really confused, and I know I'm being quite lite on the details - hopefully you can show me the proper way to do Unit Testing with Boost in Eclipse rather than whatever I'm currently doing.
Compile your application in eclipse first normal without unit tests.
After that create a new Project and reference it to the former Project with your application.
Than you create a main.cpp and insert your unit tests there.
You should be able to use the other projects classes from the new Project. Therefore, you are able to Instantiate Objects and do your asserts or whatever you like. If you have any further questions, please post your actual error and provide a screen-shot of your current structure.

Migrate from MSTest to XUnit

We are thinking about moving our tests from MSTest to XUnit.
Is there any migration application that takes a MSTest and migrates it to XUnit?
Also, if not, what should I look out for when doing this?
Thanks.
JD.
I moved quite a few tests recently. It depends on how many and what type of tests you're converting, and you didnt kill yourself giving us details. In general, I think its safe to assume that your average MSTest minded shop wont be massively Test Infected and thus wont have delved into each dark corner of MSTest.
All the Assert.* methods and the basic Test Attributes are simple find and replaces. The more rare ones, I'd generally steer towards assessing each case individually. Unless you're already a xUnit.net expert, you've got lots to learn and this will help you.
Also, usage of Assert.Fail isnt a simple transformation. The other thing is the transformation of TestClassInitialize to IUseFixture - simple to do, but hard to automate.
If people are using Test References, you won't be able to remove the reference to the MSTest assembly (and you'll still need to have VS on your build server - and it will continue to randomly fail on the Shadow taks, see my questions).
The biggest manual work for me was going through the 20 lines of boilerplate in a region at the top to see whether anyone actually used any of the custom attributes before deleting them.
The main thing that would have been a lot of work had it not been for a CodeRush template was converting ExpectedException to Assert.Throws. If you havent got CodeRush or ReSharper on this job, you'd be stealing money from your employer.
Consider Compare MSTest and xUnit