Mock Thread fails

2 posts, 0 answers
  1. Edoardo
    Edoardo avatar
    5 posts
    Member since:
    Mar 2011

    Posted 11 May 2012 Link to this post

    I'm using JustMock Q1 2012 SP1 (2012.1.508.6) and when I try to create a mock of the Thread class, I get an exception.

    I tried the following methods:

    - var mock = Mock.Create<Thread>.Create(any argument);
    - var mock = Mock.Create<Thread>.Create(new Thread(delegate{}));

    Both fails whether I use the MockClass attribute or not.

    Any suggestion?
  2. Ricky
    Ricky avatar
    467 posts

    Posted 15 May 2012 Link to this post

    Hi Edoardo,
    Thanks again for contacting us. Here it is possible to mock the Thread class in one of the following two ways:

    #1 : Using Constructor.Mocked so that it does not execute the real constructor:

    var mock = Mock.Create<Thread>(Constructor.Mocked);

    #2: By injecting the original ParameterizedThreadStart argument:

    public void TestMethod1()
        var parameterizedStart = new ParameterizedThreadStart(target);
        //var mock = Mock.Create<Thread>.Create(any argument);
        var mock = Mock.Create<Thread>(parameterizedStart);
    void target(object sender)

    Hope this answers your question.

    Kind Regards
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top