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:
class Triangle {
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 triangle.dll and triangle.pdb.
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 triangle.cs.
Writing and executing the tests
Create a file named triangle_t.cs into the same directory as triangle.cs with the following content:
//css_import triangle;
using NUnit.Framework;
[TestFixture]
class TriangleTest
{
[Test]
public void Fail000()
{
Assert.IsFalse(Triangle.Is(0, 0, 0));
}
}
Right click 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 Fail000 test.
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 if28is already used). - Within the 28.Test with directory create a file named
00.NUnit.c.cmdwith the following content:
@echo off
rem -------------------------------------------------
rem WARNING! Change the path of NUnit accordingly
set NUNIT_PATH=%ProgramFiles%\nunit 2.5.5\bin\net-2.0
rem -------------------------------------------------
set CSPATH=
set CSNAME=
for %%I in (%1) do (
set CSPATH=%%~pI
set CSNAME=%%~nI
)
set DLLNAME=%CSPATH%%CSNAME%.dll
@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%" ...
"%NUNIT_PATH%\nunit.exe" "%DLLNAME%"
:Error
pause - 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.
Conclusions
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.

4 comments:
I have never heard of such kind of testing means testing a mouse. Thanks for making me aware of about it. Software Testing Services
Amazing blog to be in! thanks for sharing the 2 CS-Script and NUnit and also a newbie in software testing!
Software Testing CV
I'm not sure I understand your concept? Wouldn't you have to write the test cases explicitly in triangle_t.cs anyway?
What is the benefit of being able to run the tests from Explorer as opposed to run them directly from VS?
Hi Simon
The benefit is that you try at once what it pops up into your head.
In development, for instance, compare programming in C# (write, save, compile, run) with trying out little piece of code in Python at the interpreter's prompt.
Mouse testing compares somewhat to the latter.
Post a Comment