Menu

#100 Abstract tests result in a null reference exception

Version 2.6
open
csUnitCore (11)
7
2009-10-10
2009-08-31
Mike Jones
No

I need to be able to do this using csUnit (the code is the same):

http://weblogs.asp.net/nunitaddin/archive/2004/05/18/134151.aspx

A base test is written with an abstract factory method which is implemented in a subclass to return an implementation of the interface which the base test verifies. It is essential for writing contract tests for interfaces.

Two issues:

1) If the namespace containing the abstract test is executed, the test runner throws a null reference exception (see below):

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="mscorlib"
StackTrace:
Server stack trace:
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at csUnit.Ui.Controls.TabPages.TestHierarchyControl.OnTestPassed(Object sender, TestResultEventArgs args)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData)
at csUnit.Interfaces.TestEventHandler.EndInvoke(IAsyncResult result)
at csUnit.Core.Loader.TestEventSink.TestEventHandlerAsyncCallback(IAsyncResult ar)
at System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(IMessage msg)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall()
at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(Object o)
at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
InnerException:

2) The results are not reported on the csUnit GUI when only the subclass implementation of the test is executed, through the subclassed test itself seems runs properly, as I am able to step through it with the debugger.

While no exception is thrown when the Ignore attribute is placed on the base class, it will prevent the subclass from being executed, as it is inherited.

I'm willing to help find a solution.

Discussion

  • Manfred Lange

    Manfred Lange - 2009-08-31

    Mike,

    thanks for submitting, including all the details and the link to an example. Thank you for your willingness to find a solution. I'm sure I'll come back with questions.

    Kind regards,
    Manfred.
    ---
    Manfred Lange
    csUnit developer
    http://www.csunit.org

     
  • Manfred Lange

    Manfred Lange - 2009-08-31
    • labels: 517853 --> csUnitCore
    • assigned_to: nobody --> malange
     
  • Mike Jones

    Mike Jones - 2009-08-31

    If something a little closer to home would be helpful, here's the source from a single file which reproduces this issue:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using csUnit;

    namespace CalvaryGrace.Core.Test.SermonSystem.Temp
    {
    public interface ISomething
    {
    bool SomeFunc();
    }

    public class Something : ISomething
    {
    #region ISomething Members

    public bool SomeFunc()
    {
    return true;
    }

    #endregion
    }

    public class ParticularTest : BaseTest
    {
    protected override ISomething CreateSomething()
    {
    return new Something();
    }
    }

    [TestFixture]
    public abstract class BaseTest
    {
    private ISomething patient;

    [SetUp]
    public void SetUp()
    {
    this.patient = CreateSomething();
    }

    protected abstract ISomething CreateSomething();

    [Test]
    public void TestSomeFunc()
    {
    Assert.True(patient.SomeFunc());
    }
    }
    }

     
  • Manfred Lange

    Manfred Lange - 2009-10-10
    • priority: 5 --> 7
     

Log in to post a comment.