Strips all testing code from an assembly.
See Milestones for release notes.
This is an add-in for Fody
It is expected that all developers using Fody either become a Patron on OpenCollective, or have a Tidelift Subscription. See Licensing/Patron FAQ for more information.
See also Fody usage.
Install the Scalpel.Fody NuGet package and update the Fody NuGet package:
PM> Install-Package Fody
PM> Install-Package Scalpel.Fody
The Install-Package Fody
is required since NuGet always defaults to the oldest, and most buggy, version of any dependency.
Add <Scalpel/>
to FodyWeavers.xml
<Weavers>
<Scalpel/>
</Weavers>
When the compilation constant Scalpel
is detected.
- Removes all types ending in
Tests
. - Removes all types ending in
Mock
. - Removes all types marked with
Scalpel.RemoveAttribute
. - Removes all references as defined in
<Scalpel RemoveReferences='XXX'/>
see below.
- Removes all types marked with any Nunit attribute.
- Remove the NUnit reference.
- Removes all types containing an XUNit attribute.
- Removes the Xunit reference.
- Removes all types containing a field from
Machine.Specifications
orMachine.Specifications.Clr4
- Removes the Machine.Specifications.Clr4 and Machine.Specifications references.
- Removes all types that implement
ISupplementSpecificationResults
,IAssemblyContext
orICleanupAfterEveryContextInAssembly
.
- Removes the reference to NSubstitute.
- Removes the reference to FakeItEasy.
- Removes the reference to Moq.
When coding any tests then these tests should be a first class citizen to the functionality you are creating. As such it makes sense for them to be co-located with the code being tested. Unfortunately due to the nature of .net this is very difficult to achieve. The reason is that if you place tests next to the code being tested you and up having those tests include in your deployable assembly. You also have the problem of your assembly referencing unit test helper libraries like NUnit and Moq.
So Scalpel helps you work around the above problem by striping tests and references from your assembly. It also has the added side effect of allowing you to test internal types without needing to use the InternalsVisibleToAttribute.
One problem with this approach is testing your deployable artifacts if the tests are removed from them.
This is a legitimate problem. The recommended approached it to create another build configuration call Deployable
. It can have all the same settings as your Release
configuration with the addition of the Scalpel
compilation constant.
This way tests can run from your Release
configuration and you can deploy from your Deployable
configuration.
All configuration options are access by modifying the Scalpel
node in FodyWeavers.xml
A list of assembly names to removed at compile time.
Do not include .exe
or .dll
in the names.
Can take two forms.
As an element with items delimited by a newline.
<Scalpel>
<RemoveReferences>
Foo
Bar
</RemoveReferences>
</Scalpel>
Or as a attribute with items delimited by a pipe |
.
<Scalpel RemoveReferences='Foo|Bar'/>
Exacto Knife designed by Edward Boatman from The Noun Project.