XUnit Test different results under netcoreapp1.1 and net462

被刻印的时光 ゝ 提交于 2020-02-08 06:09:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!