The screenshots are made using Visual Studio 2008 Pro, but you should be able to create the test scripts using Visual Studio 2010 Express as well, as long as yo don't use any .NET v4 specific features.
First set up your environment so you can run test script. I've explained it in the "Test procedure MapWindow GIS" tutorial.
All scripts must at least pass the suggestions made by Microsoft StyleCop. It will check the used naming convention of the variables and such.
First copy "_TestingScriptTemplate.cs", it is in C:\dev\TestingScripts\.
The copied file should be appropriately named, indicating approximately what it does or what it tests. The template has some comments you should use to explain what the script is doing.
Don't start with an underscore, because the test tool will ignore files that start with it.
The naming convension is for scripts that are related to bugs to name them Bugs-###-description, where ### is the bug number.
In this article I'm going to create a test script for bug #1582. So the name of the script will be Bug-1582-ClipGridWithPolygon.cs
If you're going to test a specific class you need to start with that. So all test scripts that test MapWinGeoProc methods start with MapWinGeoProc_
Let's start.Open C:\dev\TestingScripts\TestingScripts.sln and open the copied script. I've made several projects look for the one to add the scripts to. The default project is 'Scripts'.
If you open the script in the editor you should see something like this:
Start by adding the correct filename in the first line.
Change the comment in lines 16-21. When creating a script for a bug, put in the description from Mantis.Rename the public class to something unique and change the line that reads
const string ScriptName = "<<your name>>";to
const string ScriptName = "Bug-1582-ClipGridWithPolygon";This should be the name of your script without the extention.
Your scripts should look like this:
Now we can start making the actual test.
First we need to know where the test data is. In most cases you don't need specific data but you can use some of the available data.
By default the working folder is the folder with the same name as scriptName.
Use this syntax to use files from other locations:
String workingFolder = testsMethods.WorkingFolder.Replace(scriptName, @"General\MapWindow-Projects\UnitedStates\Shapefiles");
For this bug script we do need some specific data. So we create a new folder called 'Bug-1582-ClipGridWithPolygon' in C:\dev\TestingScripts\ScriptData and we put the test data in it.
Don't forget to 'SVN Add' this data as well if you're going to add the script!
For this script we need to open a shapefile and a grid file and call MapWinGeoProc.SpatialOperations.ClipGridWithPolygon()
The template uses the TestMethods() class. This class holds a lot of handy methods for commonly used actions that will help you create test scripts very fast.
Like OpenShapeFile() if will return a shapefile object or an exception is somehow it failed.
The complete script will be [download]:
How to runYou can of course run the script in the Testing tool, but it might be better to run it in the scripting editor of MapWindow (Plug-ins --> Scripts) first.
Just copy the content of your script from Vis. Studio and paste it in the script editor. Do check if you've selected C# and not VB.NET.
With a little trick Brian Marchionni thought me you can even debug the scripts. For this reason a project called "DebuggingPlugin" is available in the TestingScripts solution.
First close your script in Vis. Studio. Go to the project and add the script to that project. Now open the _DebuggingPlugin.cs file and go to ItemClicked method. It is in lines 58-64.
Change line 62 and put in the class name of your script. In this example that would be BUG1582.ScriptMain(this.mapWin);. Now add your breakpoints and run the script. It will start MapWindow and it will create a new plug-in called "DebuggingPlug-in". Enable it in the plug-ins menu and you'll get a new menu. Select 'Run test script' and your script will be run and the breakpoints will be used.
More samplesI will add another sample shortly that will show the use of screen shots to determin if the scripts are doing what they should be doing.
Also look at some of the other scripts in SVN for more examples.