我在VS 2017中创建了一个XUnit测试项目,其目标框架是netcoreapp1.1,下面的代码工作正常。
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();
}
}
}
但是,如果我将targetframework更改为net462,则不会发现测试 我错过了什么吗? 任何帮助将不胜感激。