GSoC/GCI Archive
Google Code-in 2010 Mono Project

Gendarme rule for Assert.* unit tests calls

completed by: Yuri Stuken

mentors: spouliot


Gendarme is a static analysis tool to find problems in .NET software. Gendarme inspects executables and libraries that contain code in ECMA CIL format (Mono and .NET) and looks for common problems with the code, problems that compiler do not typically check or have not historically checked.



The task is to write one Gendarme rule that ensure that all Assert.* method calls are providing a string 'message' parameter to ease locating the issue if the assrtion fails. An exception must be made if only a single call to one Assert.* method is done in a method (since locating the issue will be easy). The rule could be named 'ProvideMessageOnAssertCallsRule'.

Since this is a special rule it needs to be located in a new assembly, e.g. Gendarme.Rules.NUnit.dll, and ensure that NUnit.Framework.dll is referenced by the assembly being analyzed (otherwise the rule must turn off itself). This last step should be in a separate abstract rule so it can be reused for other, future, rules about unit testing.

Also please note the extra requirement to provide a patch to fix all such issues in Gendarme unit tests.



To complete the task the student must provide:

*  the rules, written in C#. The source code must follow the Mono source code guidelines (available at Also a 'self-check' must be done one the code (i.e. you need to run gendarme on your own code) and the defects, if any, must be fixed (in doubt please ask for guidance on IRC).

* its documentation (in-source xmldoc) that includes 'good' and 'bad' examples; and

* the unit tests (also in C# using the gendarme helpers around NUnit) proving the rule is working as intended

* a patch to fix all such issues (if any) in Gendarme unit tests

Once ready the files (or the patch) can be submitted to the mentor for review.



* In order to avoid misunderstandings you should start by writing your unit tests and ask for a review of them. That will quickly tell you if you're on the right path to solve the problem.

* Gendarme provides hundreds of rules that can be used as example, here's one





* Gendarme web site:

* Mailing-list / discussions:

* IRC: #gendarme on GimpNET