Question

I have created MSTest using Spring. In this test I use TestContext.

[TestClass]
public class Test : AbstractDependencyInjectionSpringContextTests
{
    [TestMethod]
    public void Test()
    {
    }

    protected override string[] ConfigLocations
    {
        get
        {
            return new string[] { "~/Configuration/spring.config"};
        }
    }

    public TestContext TestContext { get; set; }
}

When I run the test I get the following error:

Unsatisfied dependency expressed through object property 'TestContext': Set this property value or disable dependency checking for this object..

How can I disable the dependency injection for the TestContext property?

Was it helpful?

Solution

By default Spring.net uses autowire by type to populate properties on TestClasses; iirc you can override this by forcing field level injection. You might find this earlier answer of mine useful when configuring field level injection on tests. I think this is the way to go in your case.

Disabling dependency checking for the TestContext property would require configuring your Test class, which would basically defeat the purpose of using AbstractDependencyInjectionSpringContextTests in the first place. I think this is a normal autowire message that's somewhat misleading in the context of integration testing.

You can opt not to use dependency injection at all by not inheriting from AbstractDependencyInjectionSpringContextTests, but from it base classAbstractSpringContextTests; but that has the downside of not doing any injection at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top