Tuesday, November 26, 2013

Enable MbUnit Tests within Resharper 7.1 and Higher

Introduction

It is not possible to run unit tests written with the MbUnit test framework from within Resharper 7.1 and higher. To allow you to run them using Resharper you have to install a plugin.

Download

Install

Unzip and place them inside the following folder:
C:\Program Files (x86)\JetBrains\ReSharper\v7.1\Bin\plugins\


References


Gallio : Automated Integration Tests Autocad

1.     Introduction

Gallio is a very flexible, and extensible testing framework usedto run tests against the code that depends on the AutoCAD API.

2.     Download

Get the lastest version of Gallio at http://www.gallio.org

3.     Extract Gallio

Extract the downloaded .zip file to any location on your computer.
Before you extract the ZIP file, be sure to check its properties and click “Unblock” if that option is available.

4.     Setup MSVS 2012 (Existing or new project)

Add References

·         acdbmgd.dll (Autocad)
·         acmgd.dll (Autocad)
·         Gallio.dll, MbUnit.dll (The default Gallio test runner looks for tests written in your DLL that use the MbUnit testing framework.)

Configuration

·         Make sure you set your target framework correctly
·         External References should be set to 'Copy Local'= false (otherwise netload assemblies won't work)

5.     Create Batch

Create a .bat file and add the following code to it:
SET GALLIO_RUNTIME_PATH=C:\Users\Mysth\Downloads\GallioBundle-3.4.14.0\bin\
"C:\Users\Mysth\Downloads\GallioBundle-3.4.14.0\bin\Gallio.Echo.exe" gallio.dll /r:AutoCAD
pause

Place the batch alongside the assembly containing the tests.

6.     Reports

Gallio can generate reports with the results of the tests run in either html format or xml format.
Add the following to the batch to auto generate reports :
SET GALLIO_RUNTIME_PATH=C:\Data\GallioBundle-3.4.14.0\bin
"C:\Data\GallioBundle-3.4.14.0\bin\Gallio.Echo.exe" BRail.InfraNet.IntegrationTests.Domain.dll /r:AutoCAD/rt:xml /rt:html
Pause
Example run on BRail.InfraNet.Domain assembly



7.     Example

For this example to work add an extra assembly BeDeveloped.Framework.AutoCad.dll to your project.



Create a Test Class where our tests will be written in.
publicclassTests
    {
        [Test]
publicvoidTestCircleEqual()
        {
var services = newActiveServices();

services.EntityService.CreateCircle(0, 0, 20);

var id = services.DocumentService.GetLast();
var circle = services.EntityService.GetEntity(id) asCircle;

if (circle != null)
            {
Assert.AreEqual(20, circle.Radius);
            }
        }

[Test]
publicvoidTestCircleNotEqual()
        {
var services = newActiveServices();

services.EntityService.CreateCircle(0, 0, 10);

var id = services.DocumentService.GetLast();
var circle = services.EntityService.GetEntity(id) asCircle;

if (circle != null)
            {
Assert.AreEqual(20, circle.Radius);
}
        }
    }



Build your project and run the previously configured .bat file. Gallio should launch Autocad, load all the necessary assemblies and execute all tests. Gallio will close Autocad once all tests are executed.  You should see the following test result.
One test passedone should have failed.



8.     Known Issues

System.NotSupportedException:
An attempt was made to load an assembly
from a network location which would have caused the assembly to be sandboxed in
previous versions of the .NET Framework. This release of the .NET Framework
does not enable CAS policy by default, so this load may be dangerous. If this
load is not intended to sandbox the assembly, please enable the
loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569
for more information.