Build/Test Issues

Unable to cast object of type 'STATestCase' to type 'Xunit.Sdk.XunitTestCase'.

Started by sjkirk on 4,802 views

As I mentioned before I'm trying to get the GitHub for Visual Studio extension working with NCrunch, but I've hit another problem.

In ours tests we use STATestCase (from here): https://github.com/github/VisualStudio/blob/master/src/UnitTests/XUnit/STATestCase.cs

I'm getting the following error from NCrunch:

An error occurred while analysing this project after it was built: System.Exception: Exception during discovery:
System.InvalidCastException: Unable to cast object of type 'STATestCase' to type 'Xunit.Sdk.XunitTestCase'.
at nCrunch.Module.XUnit2.Integration.XUnitDiscoveryMessageSink.OnMessage(IMessageSinkMessage message)
at nCrunch.Module.XUnit2.Integration.XUnitMessageSinkAdapter.OnMessage(IMessageSinkMessage message)
at Xunit.Sdk.SynchronousMessageBus.QueueMessage(IMessageSinkMessage message)
at Xunit.Sdk.XunitTestFrameworkDiscoverer.FindTestsForMethod(ITestMethod testMethod, Boolean includeSourceInformation, IMessageBus messageBus, ITestFrameworkDiscoveryOptions discoveryOptions)
at


As you can see from the code, STATestCase implements IXunitTestCase but does not derive from XunitTestCase. Could NCrunch use the IXunitTestCase interface instead?
Hi, thanks for sharing this problem.

This change has recently been requested and it seems to be getting quite popular (see https://ncrunch.uservoice.com/forums/245203-feature-requests/suggestions/16474246-to-support-custom-xunit-test-cases).

It may actually be as simple as just switching to the interface. I'll need to investigate further. Toolsets that implement their own tests under the hood can sometimes implement unexpected logic that NCrunch can't handle (NUnit saw lots of this), so it's hard for me to promise that this will work perfectly under NCrunch. I'll see what I can do about including something for this in the V3 release due out in the next few weeks.

Post a reply

Log in to reply.