问题
I created a XUnit test projects in VS 2017, its target framework is netcoreapp1.1, and below code works correctly.
using Xunit;
using Xunit.Abstractions;
using Xunit.Ioc.Autofac;
namespace XUnitTestProject2
{
[UseAutofacTestFramework]
public class MyAwesomeTests
{
public MyAwesomeTests()
{
}
public MyAwesomeTests(ITestOutputHelper outputHelper)
{
_outputHelper = outputHelper;
}
[Fact]
public void AssertThatWeDoStuff()
{
_outputHelper.WriteLine("Hello");
}
private readonly ITestOutputHelper _outputHelper;
}
}
using Autofac;
using System.Reflection;
using Xunit;
using Xunit.Abstractions;
using Xunit.Ioc.Autofac;
using Xunit.Sdk;
[assembly: TestFramework("XUnitTestProject2.ConfigureTestFramework", "XUnitTestProject2")]
namespace XUnitTestProject2
{
public class ConfigureTestFramework : AutofacTestFramework
{
private const string TestSuffixConvention = "Tests";
public ConfigureTestFramework(IMessageSink diagnosticMessageSink)
: base(diagnosticMessageSink)
{
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(typeof(ConfigureTestFramework).GetTypeInfo().Assembly)
.Where(t => t.Name.EndsWith(TestSuffixConvention));
builder.RegisterType<TestOutputHelper>().AsSelf().As<ITestOutputHelper>().InstancePerLifetimeScope();
// configure your container
// e.g. builder.RegisterModule<TestOverrideModule>();
Container = builder.Build();
}
}
}
But, if I change the targetframework to net462, there will not tests be found.
Did i miss anything?
Any help would be appreciated.
来源:https://stackoverflow.com/questions/43537944/xunit-test-different-results-under-netcoreapp1-1-and-net462