Running tests with jni4net bridge code using nunit

192 Views Asked by At

I am writing some tests for a project that bridges a java component into C# using jni4net. I am able to run the tests using resharper with no issues, but nunit seems to be unable to locate the needed jar

        var setup = new BridgeSetup(true);
        string jarPath = System.Web.Hosting.HostingEnvironment.MapPath("~/bin/lib");
        if (jarPath != null)
        {
            setup.AddAllJarsClassPath(jarPath);
        }
        setup.BindStatic = false;
        Bridge.CreateJVM(setup);
        string jdbcUrl = "jdbc:somedriver:localhost";
        _conn = DriverManager.getConnection( jdbcUrl );

The error happens at DriverManager.getConnection() looking for a jdbc driver, which is located in the path given ~/bin/lib

1

There are 1 best solutions below

0
On BEST ANSWER

We were able to find a solution to the issue.

NUnit runner by default runs tests in a separate thread, meaning in the java bridge was being initialized on a thread that the tests were not running which caused the tests to not have access to the need .jar files

NUnit runner has a command line option /nothread to suppress the use of a separate thread for tests. More info can be found here