C# NUnit无法运行

C# NUnit无法运行,c#,.net,nunit,C#,.net,Nunit,我有一个简单的NUnit代码无法工作,如下所示: [TestFixture("abc", "xyz", typeof(int))] public class GenericTestFixture<T> { T tt; string aa; string bb; public GenericTestFixture(string a, string b, T t) {

我有一个简单的NUnit代码无法工作,如下所示:

[TestFixture("abc", "xyz", typeof(int))]
    public class GenericTestFixture<T>
    {
        T tt;
        string aa;
        string bb;
        public GenericTestFixture(string a, string b, T t)
        {
            tt = t;
            aa = a;
            bb = b;
        }

        [Test]
        public void Test1()
        {
            Debug.WriteLine($"aa is {aa}, bb is {bb}, t is {typeof(T).ToString()}");
        }


        [TestCase(1)]
        public void TestMethod(int c)
        {
            Assert.Equals(c, 1);
        }
    }
您需要遵循doc,如下所示:

[TestFixture(typeof(int), "abc", "xyz")]
public class GenericTestFixture<T>
{
    private readonly string _aa;
    private readonly string _bb;


    public GenericTestFixture(string a, string b)
    {
        _aa = a;
        _bb = b;
    }


    [Test]
    public void Test1()
    {
        Debug.WriteLine($"aa is {_aa}, bb is {_bb}, t is {typeof(T)}");
    }


    [TestCase(1)]
    public void TestMethod(int c)
    {
        Assert.AreEqual(c, 1);
    }
}
[TestFixture(typeof(int),“abc”,“xyz”)]
公共类GenericTestFixture
{
私有只读字符串_aa;
私有只读字符串_bb;
公共GenericTestFixture(字符串a、字符串b)
{
_aa=a;
_bb=b;
}
[测试]
公共void Test1()
{
WriteLine($“aa是{uaa},bb是{ubb},t是{typeof(t)}”);
}
[测试用例(1)]
公共void测试方法(intc)
{
断言.AreEqual(c,1);
}
}
调试输出:


在Visual Studio的“输出”窗口中,将“显示输出”下拉列表更改为“测试”。这将向您显示测试运行的控制台输出,并可能包括来自NUnit3TestAdapter的一些错误消息。如果是这样,请在这里添加它们。谢谢,上面的代码可以工作,但是如果我在“xyz”后面加上typeof(int),那么它就不能在我的更新中使用相同的日志消息。原因是什么?根据文档,必须在前导参数或命名参数TypeArgs=new type[]{typeof(int)}中指定类型。
[TestFixture(typeof(int), "abc", "xyz")]
public class GenericTestFixture<T>
{
    private readonly string _aa;
    private readonly string _bb;


    public GenericTestFixture(string a, string b)
    {
        _aa = a;
        _bb = b;
    }


    [Test]
    public void Test1()
    {
        Debug.WriteLine($"aa is {_aa}, bb is {_bb}, t is {typeof(T)}");
    }


    [TestCase(1)]
    public void TestMethod(int c)
    {
        Assert.AreEqual(c, 1);
    }
}