First encounters w ith unit testing in C#.NET

Encoder QR Code in C#.NET First encounters w ith unit testing

First encounters w ith unit testing
Draw Quick Response Code In Visual C#
Using Barcode generation for .NET framework Control to generate, create QR-Code image in .NET applications.
www.OnBarcode.com
Read Quick Response Code In C#
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Figure 6.2 execute.
Make DataMatrix In C#.NET
Using Barcode creation for .NET framework Control to generate, create ECC200 image in .NET framework applications.
www.OnBarcode.com
Generating Matrix Barcode In Visual C#
Using Barcode creator for VS .NET Control to generate, create 2D image in VS .NET applications.
www.OnBarcode.com
The CiDotNet.Calc.Test assembly is loaded into the NUnit GUI test runner and ready to
Creating Barcode In Visual C#.NET
Using Barcode generator for VS .NET Control to generate, create Barcode image in VS .NET applications.
www.OnBarcode.com
PDF-417 2d Barcode Generation In Visual C#.NET
Using Barcode generation for .NET framework Control to generate, create PDF 417 image in .NET applications.
www.OnBarcode.com
Figure 6.3 If all the tests pass, you see a green bar in the right pane. The left pane shows a check mark inside a green circle next to each passing test.
EAN13 Generation In C#.NET
Using Barcode generator for Visual Studio .NET Control to generate, create EAN-13 Supplement 5 image in .NET framework applications.
www.OnBarcode.com
GS1 - 12 Generation In C#
Using Barcode creator for .NET Control to generate, create UPCE image in .NET framework applications.
www.OnBarcode.com
with the [Ignore] attribute (in addition to the [Test] attribute), NUnit skips execution and shows a yellow result when you run the test. Copy the test again, change the name to FailOnPurpose(), and decorate it with the [ExpectException] attribute. This informs the NUnit framework that you expect the tested code to cause an exception. Run the test DLL in the GUI test runner, and you ll get the colorful output shown in figure 6.4. All the GUI tests are of course useless in the CI environment. The CI server isn t as smart as you are and can t use GUI tools. You need something that you ll be able to start from a build script something that will perform the tests and save the output in a text file. To do this, you can use a command-line test runner. You ll hook it up to CruiseControl.NET (CCNet).
QR Code Generation In Java
Using Barcode drawer for BIRT reports Control to generate, create QR Code JIS X 0510 image in Eclipse BIRT applications.
www.OnBarcode.com
Creating QR Code ISO/IEC18004 In Java
Using Barcode drawer for Java Control to generate, create QR image in Java applications.
www.OnBarcode.com
M arrying N Unit w ith CruiseControl.NET
Paint Barcode In Java
Using Barcode maker for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
Painting Matrix Barcode In .NET
Using Barcode maker for VS .NET Control to generate, create 2D Barcode image in .NET applications.
www.OnBarcode.com
If you want to integrate the unit tests with your CI server, you ll use a command-line tool and script the process in the build script. NUnit comes with a suitable command-line test
EAN-13 Supplement 5 Reader In Visual C#.NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Barcode Creator In Objective-C
Using Barcode printer for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Unit testing continuously integrated code
QR Code ISO/IEC18004 Generation In VS .NET
Using Barcode generator for .NET framework Control to generate, create Denso QR Bar Code image in .NET applications.
www.OnBarcode.com
Recognizing Universal Product Code Version A In VB.NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Figure 6.4 If a single test fails, you get a red result in the right pane. The left pane shows an X inside a red circle for failing tests, which bubble up all the way to the top-level assembly. One test, CalculateRate(), passed. The IgnoreTest() method didn t run, so it displays a question mark inside a yellow circle.
Create Barcode In .NET
Using Barcode maker for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
UCC - 12 Printer In None
Using Barcode creation for Online Control to generate, create UPC-A Supplement 5 image in Online applications.
www.OnBarcode.com
runner. Add the nunit-console.exe file and all the dependencies (nunit-console-runner. dll, nunit-console.exe, nunit.core.dll, nunit.core.interfaces.dll, nunit.framework.dll, and nunit.util.dll) from the NUnit zip file that you downloaded earlier to the tools directory. To execute the tests you created earlier, issue the following command:
Generating Barcode In Java
Using Barcode creation for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
EAN 128 Generation In Java
Using Barcode generation for Java Control to generate, create EAN128 image in Java applications.
www.OnBarcode.com
C:\Dev\CiDotNet>lib\NUnit\nunit-console.exe
CiDotNet.Calc.Test\bin\Debug\CiDotNet.Calc.Test.dll
The console test runner will perform all the tests, as shown in figure 6.5. In chapter 3, you chose MSBuild as your build engine of choice. You need NUnit to run from within the MSBuild script. There s an MSBuild Community Task (see chapter 3) to run NUnit that you can use, but you ll now execute it using the exec task as follows.
NUnit console test runner executing from the command line and performing the tests
First encounters w ith unit testing
Listing 6.3 MSBuild script running the NUnit tests
<Project DefaultTargets="Build;Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' "> Debug </Configuration> <TestAssemblies> CiDotNet.Calc.Test\bin\$(Configuration)
\CiDotNet.Calc.Test.dll </TestAssemblies> </PropertyGroup> <Target Name="Build" > <MSBuild Targets="Clean;Rebuild" Projects="CiDotNet.sln" ContinueOnError="false" /> </Target> <Target Name="Test" > <Exec Command="lib\NUnit\nunit-console.exe $(TestAssemblies)
</Target> </Project> /xml=NUnitReport.xml"/>
Launches NUnit and runs tests
As you can see, you start the Test target that uses the exec task to execute the nunitconsole.exe application, providing it with the property that contains the DLL to test. The /xml parameter tells NUnit to create an XML report file. You ll use this file on the CI server to integrate the test results within the feedback mechanism. The build script contains the target named Build, which compiles and rebuilds the whole solution. You can use it directly as a build script on the CI server. If your project resides in a revision-control system (we described how to put it there in chapter 2) and you re still using the CruiseControl.NET configuration from chapter 3, then you re good to go. Update the MSBuild script according to listing 6.3, check everything in, and your CI process will snap in and perform the build followed by the test. Let s quickly glance at the Web Dashboard to see if everything works correctly (see figure 6.6). You can see a lot on the CCNet Dashboard page. It integrates easily with various test tools. The test tool must be able to produce XML-formatted output; CCNet applies an
Figure 6.6 CCNet Web Dashboard with a failing project. A red bar under the project is a quick indicator that something's wrong.
Copyright © OnBarcode.com . All rights reserved.