With Instrumentation Mode set to Optimized I'm seeing MSpec behaviors with generic types fail when instrumented with a custom type (though not with .NET types such as Object or String). After changing the instrumentation mode to Legacy everything works as expected.
Requirements:
Latest Machine.Specifications and Machine.Specification.Should NuGet packages.
NCrunch instrumentation mode set to Optimized.
// Everything works as expected for this test (one test passes and one test fails)
public class when_concrete_type_is_string : TestBehavior<String> {
Establish context = () => {
Console.Out.WriteLine("Context ran.");
};
Behaves_like<TestBehavior<String>> a_test_object = () => { };
}
// Both tests fail with this message:
// This test was not executed during a planned execution run.
// Ensure your test project is stable and does not contain issues in initialisation/teardown fixtures.
public class when_concrete_type_is_test_object : TestBehavior<TestObject> {
Establish context = () => {
Console.Out.WriteLine("Context ran.");
};
Behaves_like<TestBehavior<TestObject>> a_test_object = () => { };
}
[Behaviors]
public class TestBehavior<T> {
It should_run_passing_test = () => {
true.ShouldBeTrue();
};
It should_run_failing_test = () => {
false.ShouldBeTrue();
};
}
public class TestObject {
}
Let me know if you need me to gather any additional information for you.
This fixed behaviors with one generic argument, but behaviors with two generic arguments are still broken (I haven't tried more than two). This can be reproduced using the code in the original post by changing TestBehavior<T> to TestBehavior<T, U> and passing the same type a second time everywhere it's used (e.g. TestBehavior<TestObject, TestObject>). The error message is the same.
ljohnston wrote:
This fixed behaviors with one generic argument, but behaviors with two generic arguments are still broken (I haven't tried more than two). This can be reproduced using the code in the original post by changing TestBehavior<T> to TestBehavior<T, U> and passing the same type a second time everywhere it's used (e.g. TestBehavior<TestObject, TestObject>). The error message is the same.
Thanks for picking this up. We'll see if we can get it fixed.
ljohnston wrote:
This fixed behaviors with one generic argument, but behaviors with two generic arguments are still broken (I haven't tried more than two). This can be reproduced using the code in the original post by changing TestBehavior<T> to TestBehavior<T, U> and passing the same type a second time everywhere it's used (e.g. TestBehavior<TestObject, TestObject>). The error message is the same.
I'm having some trouble reproducing this as you've described. It seems to work correctly for me. Is there any chance you can share a code sample with me?
Sorry about the delay, I didn't get a notification for your latest reply (I think I must have viewed the previous one without logging in/using the link from the email).
Here's an updated sample (which appears to fail in the same way as the previous one did):
// Everything works as expected for this test (one test passes and one test fails)
public class when_concrete_type_is_string : TestBehavior<String, String> {
Establish context = () => {
Console.Out.WriteLine("Context ran.");
};
Behaves_like<TestBehavior<String, String>> a_test_object = () => { };
}
// Both tests fail with this message:
// This test was not executed during a planned execution run.
// Ensure your test project is stable and does not contain issues in initialisation/teardown fixtures.
public class when_concrete_type_is_test_object : TestBehavior<TestObject, TestObject> {
Establish context = () => {
Console.Out.WriteLine("Context ran.");
};
Behaves_like<TestBehavior<TestObject, TestObject>> a_test_object = () => { };
}
[Behaviors]
public class TestBehavior<T, U> {
It should_run_passing_test = () => {
true.ShouldBeTrue();
};
It should_run_failing_test = () => {
false.ShouldBeTrue();
};
}
public class TestObject {
}