I wrote in a previous article how important is for exploratory testing to be able to try ideas quickly and to use the simplest environments, tools and languages when doing testing – especially exploratory testing. I also recommended PowerShell as the testing language for .NET.
In this article I try to introduce an alternative to testing with PowerShell. The alternative consists in running C# tests with only two right clicks of the mouse. In other words, mouse testing!
Ingredient No. 1: CS-Script
CS-Script is a simple but effective scripting engine that transforms C# into a scripting language, with all the associated advantages. Although here is not the place to describe CS-Script, a few details are worth mentioning:
- Embedded dependencies: CS-Script allows C# files to specify their own dependencies. Good bye project files, welcome incremental development.
- Windows Explorer integration: CS-Script inserts in the contextual menu of Windows Explorer a special entry with the most common functionality. This makes compiling a script as easy as issuing a right click of the mouse. Moreover, the CS-Script sub-menu is customizable.
- Conversion to Visual Studio projects: as the project represented by a script and all its dependencies grows, the user can convert it into a Visual Studio project. The original C# code remains unchanged.
The simplest way to see the power of CS-Script is to try it. Install CS-Script and save the following content into triangle.cs:
public static bool Is(int a, int b, int c)
return a > 0 && b > 0 && c > 0 &&
a < b + c &&
b < a + c &&
c < a + b;
Go to Windows Explorer, right click triangle.cs and then select
CS-Script | Compile to | DLL (Debug). CS-Script will produce
Ingredient No. 2: NUnit
NUnit is the de-facto standard for unit testing and, besides many qualities, it permits the execution of tests with the right click of the mouse. We shall rely on this feature to do “mouse testing”.
Before proceeding any further, CS-Script must have a grip on the DLLs that the tests employ from NUnit. For our example simply copy from the installation directory of NUnit the
.\bin\net-2.0\framework\nunit.framework.dll library and place it into the same directory as
Writing and executing the tests
Create a file named
triangle_t.cs into the same directory as
triangle.cs with the following content:
public void Fail000()
Assert.IsFalse(Triangle.Is(0, 0, 0));
triangle_t.cs in Windows Explorer then select
CS-Script | Compile to | DLL (Debug)) and then right click
triangle_t.dll in Windows Explorer and select
Run Tests. Windows Explorer will launch NUnit and from there you can execute the
When two is too much
If issuing two right clicks to do testing feels too much of a burden, then the whole stuff (compilation and NUnit launch) can be carried out in just one right click of mouse. This version requires a little bit more work but it’s a one time effort.
Do the following steps:
- Within the directory of CS-Script, create a directory named 28.Test with under
.\bin\Lib\ShellExtensions\CS-Script(use a higher number if
28is already used).
- Within the 28.Test with directory create a file named
00.NUnit.c.cmdwith the following content:
rem WARNING! Change the path of NUnit accordingly
set NUNIT_PATH=%ProgramFiles%\nunit 2.5.5\bin\net-2.0
for %%I in (%1) do (
@echo Copying NUnit libraries into "%CSPATH%" ...
copy /y "%NUNIT_PATH%\framework\*.dll" "%CSPATH%"
copy /y "%NUNIT_PATH%\lib\*.dll" "%CSPATH%"
if ERRORLEVEL 1 goto Error
@echo Compiling %1 ...
cscs /cd %1
if ERRORLEVEL 1 goto Error
@echo Launching NUnit with "%DLLNAME%" ...
- Replace the path to NUnit with the directory where NUnit resides on your computer (see the red text from above).
- In Windows Explorer right click triangle_t.cs and then select
CS-Script | Test with | NUnit. The underlying script will compile and run the tests under NUnit. OBS: this command copies locally all the DLLs from the NUnit distribution.
Software testing requires the ability to try quickly new ideas as the program under test is being explored by the test engineer. Simple, straightforward tools are essential for such endeavor.
With the aid of CS-Script and NUnit the software test engineer can compile and run .NET tests quickly and efficiently with just a few mouse clicks, without the need of a fully fledged development environment.