Fork me on GitHub

Using pure .cs files as load test scripts in GrinderScript.Net

If you feel that creating and compiling a C# load test project is to much overhead, you can now also run a pure .cs file directly as a load test script.

If you're not comfortable with how to write a load test with GrinderScript.Net, we recommend that you (re)visit the description of how to write load test before you continue.

You need the GrinderScript.Net.CsScript NuGet package installed to use this feature. If you've already installed the GrinderScript.Net.Samples package, you also have GrinderScript.Net.CsScript installed, otherwise you install it from the Visual Studio Package Manager Console with the command

install-package GrinderScript.Net.CsScript

or by running NuGet.exe from the command line, e.g.:

C:\Util\NuGet.exe install GrinderScript.Net.CsScript -OutputDirectory C:\MySolution\ExternalLibs

Internally GrinderScript.Net use the excellent C# script engine Cs-Script's hosting functionality to do all the hard work of dynamically loading and compiling your .cs file into code in the CLR. We uses the new CS-Script Evaluator, that is based on Mono's compiler as service. You can use all the CS-Script features that are supported in hosted evaluator mode, with one limitation: Your .cs script file must contain a class that implements the GrinderScript.Net.Core.IGrinderWorker interface. Duck typing or scripts containing only a method definition is currently not supported. Please consult the CS-Script Documentation if you want to learn more about CS-Script's features. The good news is that you can implement your worker using any of the strategies described in the Writing load tests page.

Beside writing your worker in the .cs script file, all you need to configure your grinder.properties following these three steps:

  1. Use GrinderScript.Net.CsScript.dll as the grinder.script property. The location is relative to the location of your grinder.properties.
  2. Use the ready made CsScriptWorker as the grinderscript-dotnet.workerType property.
  3. Configure the actual .cs script file with the grinderscript-dotnet.csScriptWorker.script property. The location is relative to the location of the assembly specified in the grinder.script property.

Here is the interesting parts taken from the grinder.properties in the GrinderScript.Net.Samples CsScript example:

grinder.script=..\\..\\..\\GrinderScript.Net.CsScript.dll

grinderscript-dotnet.workerType=GrinderScript.Net.CsScript.CsScriptWorker, GrinderScript.Net.CsScript

grinderscript-dotnet.csScriptWorker.script=.\\Samples\\GrinderScript.Net\\Core\\WorkerThatLogs.cs

With this in place you can use a workflow where you write some load test script in a .cs file, save the file and then run it directly from the Grinder Console, in an iterative process. The Grinder Console will automatically distribute the changed script file to all your Grinder Agents.

What's next

If youve followed the user documentation for GrinderScript.Net sequentially, your last piece of information is the complete list of properties used by GrinderScript.Net. Otherwise you should check out how to write load tests with GrinderScript.Net.