Reputation: 3182
Im trying to get to grips with using the NUnit framework.
Current structure:
Note that 'NUnitStackHandler' is my class library.
At the moment I'm getting into a bit of a mess with how to go about this the right way.
My situation is I have a c# winform with a single c# class. This class holds my methods and I then have another class library file that holds my tests - these test are the methods that have been built to go into the class file.
The situation im having is I cant seem to keep hold of the built DLL file. When i open NUnit and search for the DLL it is gone from the 'bin' folder and all I'm left with is a exe app file.
Can someone tell me if i should be referencing the DLL test methods and using them in my project instead of a separate c# file with the exact same methods?
Upvotes: 0
Views: 545
Reputation: 4285
One way you can use NUnit in your project is like so:
Create your unit tests in a seperate project something like MyApp.Tests, which will be a class library project.
Check out SOLID as it will help you in your TDD.
Inside this project you add your reference to NUnit and you can then use the tests in that project to drive out the functionality of the actually application you are attempting to create, like so:
Solution:
MyApp.Tests
MyApp
In the MyApp.Tests project you declare your tests like so:
[TestFixture]
public class TestingMyApp
{
[Test]
{
// Add you assertions here
// From here you would drive out the
// functionality on your applications class(es)
}
}
In the MyApp project you might have a class that contains the functionality and that class will be used by your application but would be the class that you build up from your tests.
Note that your tests do not actually become your methods in the class within MyApp they are used to drive out the methods you would use in the class within MyApp, if that makes sense.
On a personal point, I like using NUnit with Resharper so I can write how I want the class to be designed and where the bits I have not implemented are being highlighted in VS with red squiggly lines, I simply Alt+Enter on the squiggly lines to perform the 'driving out' of the actual implementation.
Upvotes: 1
Reputation: 3182
Ok sorted this
For those new to NUnit wishing to use it with a c winform:
Create your solution project as normal.
Once your form is created, save it.
go to file > Add > New Project... > ClassLibrary
You now have and added classLibrary project to handle tests
5.To build the DLL simply right click on the class icon and click 'build'
Upvotes: 0