Question

I'm a newbie to NUnit (in fact to unit testing in general) and I'm trying to write some tests for a little thing I'm working on.

What I'm doing is attempting to write a Wrapper library for libspotify.

An example of what I'm trying to test is:

    /// <summary>
    /// The connection state of the specified session.
    /// </summary>
    /// <param name="sessionPtr">Pointer to Session object</param>
    /// <returns>The connection state - see the ConnectionStateE enum for possible values</returns>
    [DllImport("libspotify")]
    internal static extern ConnectionStateE sp_session_connectionstate(IntPtr sessionPtr);

    /// <summary>
    /// The connection state of the session
    /// </summary>
    public ConnectionStateE GetConnectionState()
    {
        __CheckIsNotDisposed();
        return sp_session_connectionstate(this.Ptr);
    }

And then the test itself (in a separate project, same solution)

    [Test]
    public void TestSessionInitializeDisconnected()
    {
        using (var sess = new Session())
        {
            Assert.AreEqual(sess.ConnectionState, myLibSpotify.Enums.ConnectionStateE.DISCONNECTED);
        }
    }

Admittedly this test may not be the most useful but at the moment this is irrelevant. The problem I'm having is when I attempt to run the tests NUnit shows me an exception of:

    SpecTests.TestSessionBasics.TestSessionInitializeDisconnected:
    System.BadImageFormatException : An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

I'm guessing I've overlooked something here but googleing hasn't really helped because I seem to find results only for testing c++/cli or other results that don't really help.

Any help would be appreciated. Thanks.

Était-ce utile?

La solution

The solution to this was to run NUnit's 32bit binary instead of the 64bit which is default on a x64 machine.

The reason being the external library I was using was evidently compiled for x86 (32bit) and thus doesn't play nicely with code calling from a 64bit environment.

As @HansPassant mentioned, the solution came from this question: nUnit Exception on a 64 bit Machine

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top