|
Project Information
Members
Featured
Downloads
Links
|
What is NSynthesis?In practical terms, NSynthesis monitors your unit tests as they run, capturing any calls you make to a mock object. For each call to a mock, NSynthesis demands that you have executed every possible concrete implementation during the same test run. NSynthesis uses PostSharp to modify the test code only, so there are no changes required to your production code base. There are also implementations for Ruby and Java. PrerequisitesCurrently, NSynthesis requires that you are using the following tools
Let us know what other tools you'd like support for. UsageYou do not need to modify any production code. If you do, let us know and we'll try and change it. You will need to modify your test code and build scripts. If in doubt, follow the example of the project Sample.Test. Steps to get NSynthesis working are:
Extending NUnitCopy the file NSynthesis.NUnitExtension.dll to [path-to-nunit]\addins\NSynthesis.NUnitExtension.dll. Patching your test project's csproj fileIn the unit test project's .csproj file, replace <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets.--> with <PropertyGroup> <DontImportPostSharp>True</DontImportPostSharp> <PostSharpAutoUpdateDisable>True</PostSharpAutoUpdateDisable> </PropertyGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets.--> <Import Project="path\to\PostSharp.targets" /> NB: Make sure the relative path to "path\to\PostSharp.targets" is correct. In the unit test project, add references to NSynthesis.dll, PostSharp.Public.dll and PostSharp.Laos.dll. Add Watch AttributesSomewhere in your unit test assembly's code (we suggest the AssemblyInfo.cs file), include the Watch attribute e.g. [assembly: Watch(AttributeTargetAssemblies = "YourApplication", AttributeTargetTypes="*")] That example would submit all types in the MainApplication to NSynthesis' inspection. If you want generic classes to be examined, change your Watch attribute as follows: [assembly : Watch(AttributeTargetAssemblies = "YourApplication", AttributeTargetTypes = "*", MonitorGenerics = true)] Running tests from nantEnsure that you are calling nunit using the nant exec command (you cannot use the NUnit2 task) e.g
The nunit2 task does not support nunit addins, and so cannot generate the nsynthesis report file. Generating the NSynthesis reportInclude the following in your NAnt script, after you've run the unit tests. <target name="synthesis"> <loadtasks assembly="path\to\NSynthesis.Tasks.dll" /> <NSynthesis reportFile="synthesis.xml" failonerror="true" /> </target> When the synthesis target runs, it will dump a report to the command line of how many mock calls it found, and if any of them had no implementations or any untested implementations. Running the sample appIn the folder sample, run sample.bat. This demonstrates a build passes because of there are unit tests for all mocked interactions. Try disabling one or more of the repository tests to break the build. Known Limitations and Quirks
|