(Presented by Gil Zilberfeld - Product Manager)
What you will get:
Secret tips that will make you a unit testing success
What it takes to be really agile
How to test legacy code
How unit tests save you debugging time
Over 2500 of your colleagues have already participated.
These developers have stated that they
Watch the webinar to discover how you can succeed with unit testing
Register on the right and we will send you a link to the full online recording
"Gil shows an exciting approach to unit testing legacy code. Can't really think of anything you should try to improve." – Doug B, Sr. Lead
Gil Zilberfeld, Typemock's Product Manager, has over 18 years of experience and is a well know speaker at developer conferences around the world and an Agile practitioner
To watch, register on the right and we will send you a link to the full online recording.
The first tool you need is a testing framework. You have a couple of choices there. If you are using Microsoft Visual Studio 2008 Professional or above, you already have the Microsoft unit testing framework installed. The framework comes also with Microsoft Visual Studio 2005 Team System.
You may also decide to go with one of the open source frameworks: NUnit, MbUnit (now part of the Gallio project) or xUnit. There are minor differences between the different frameworks, but the main features are the same. Typemock Isolator also includes the SmartRunner, which will run tests for you inside Visual Studio.
For using the attributes and API of the different frameworks, you just need to add references to them in your test project. The Microsoft test framework has a special Test Project, the other framework uses a regular DLL container for the tests.
The next thing you need is a mocking framework, like Typemock Isolator. Follow the steps in our quick start guide how to write the first test. You'll need to add references to Isolator DLLs.
Now for your first test: In order to make it easy, let's start by testing a component you're already working on. It's very important to integrate test writing into your regular work, and that's the first step.
In your test project, create a test class, called after your class-under-test. For example if you class is called MyClass, call the test class MyClassTests.
Writing the first unit test:
Now it's time to write a test. Decide what public method you want to test, what is the specific scenario and the expected result for that scenario. Use that information to name your test. Use the following convention:
public void METHODNAME_SCENARIO_RESULT()
Now add the content of the test. A test contains three parts:
Make sure you use Assert functions to specify pass/failure functionality. You can also use Isolate.Verify for method calls as well, otherwise, the test will appear to have passed.
Run the test. If the test fails, add additional behavior setting statements with Isolator in the Arrange part, to make sure the test follows the specific scenario you're testing.
Did the test finally pass? Congratulations! You now can move to the next one.
Remember, the more tests you have, the better coverage you have, and your code becomes more stable.
|How to Start Unit Testing .NET Projects||Download Free Trial||Basic unit testing: Mocking and
|Free Webinar: Introduction to Unit Testing
||Writing Your First Unit Test in C#||Difference Between Integration Tests & Unit Tests|