R.Net and Unit Tests (NUnit)

Nov 2, 2014 at 8:46 PM
I have an issue when running test units:

I use NUnit 2.6.3 and TestDrive.Net 3.8.2860 in Visual Studio 2012
R 3.1.2 and R.NEt 1.5.16

When I run unit tests the fist time the hello world example works fine.

The problem is that:
  • TestDrive process is not finished.
  • When running NUnit GUI if I want to repeat the single test (with Hello World example) the test fails. I get the following error:
System.Exception : The single REngine instance has already been disposed of (i.e. shut down). Multiple engine restart is not possible.

w RDotNet.REngine.GetInstance(String dll, Boolean initialize, StartupParameter parameter, ICharacterDevice device)
w .UnitTests.RNetTest.HelloWorldTest() w .....UnitTests\RNetTest.cs:line 19

When I close NUnit or Kill TestDrive process and repeat the tests the result is OK.

Maybe this is a problem of Dispose() method called at the end of the test method?

Nov 2, 2014 at 11:09 PM
Not sure which unit tests you refer to; I gather they are yours as I cannot locate similar ones in the R.NET codebase.

But from what you describe, yes as you say it is because once REngine.Dispose() has been called in a process, there is no way to restart R and go through the initialisation procedure. So far as I remember this is a limitation of the R library itself, not something that R.NET can work around.
Nov 3, 2014 at 4:56 AM
You probably don't want to run many of these tests under TestDriven.Net, NCrunch, .Net Demon, or any other automatic red/green TDD runner. In fact, since its a 3rd party library, I'm not sure why you would run them. I would add them to your exclusion list.

@jperraud is correct, you cannot unload R from a .Net process since it is unmanaged.