XFEExtension.NetCore.XUnit 2.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package XFEExtension.NetCore.XUnit --version 2.0.2                
NuGet\Install-Package XFEExtension.NetCore.XUnit -Version 2.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XFEExtension.NetCore.XUnit" Version="2.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XFEExtension.NetCore.XUnit --version 2.0.2                
#r "nuget: XFEExtension.NetCore.XUnit, 2.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install XFEExtension.NetCore.XUnit as a Cake Addin
#addin nuget:?package=XFEExtension.NetCore.XUnit&version=2.0.2

// Install XFEExtension.NetCore.XUnit as a Cake Tool
#tool nuget:?package=XFEExtension.NetCore.XUnit&version=2.0.2                

XFEExtension.NetCore.XUnit

描述

XUnit测试框架,使得用户不需要编写Main函数,只需要在需要测试的类或者方法上面加上相对于的特性即可。

示例

快速编写无参测试用例(CTest和MTest)

[CTest]
//[CTest]
//可添加多个测试用例
public class TestClass
{
    [MTest]
    //[MTest]
    //[MTest]
    //可添加多个测试用例
    public void TestMethod()
    {
        Console.WriteLine("Hello World!");
    }
}

带参数的测试用例

[CTest]
public class TestClass
{
    [MTest(1, 2)]
    [MTest(2, 3)]
    [MTest(3, 4)]
    public void TestMethod(int a, int b)
    {
        Console.WriteLine(a + b);
    }
}

使用断言(通过继承类)

[CTest]
public class TestClass : XFECode
{
    [MTest(1, 2)]
    [MTest(2, 3)]
    public void TestMethod(int a, int b)
    {
        Assert(a + b == 3, "不等于3");
    }
}

使用断言(不继承)

[CTest]
public class TestClass
{
    [MTest(1, 2)]
    [MTest(2, 3)]
    public void TestMethod(int a, int b)
    {
        XFECode.Assert(a + b == 3, "不等于3");
    }
}

判断返回值是否相等(MRTest)

[CTest]
public class TestClass
{
    [MRTest(1, 2, 3)]
    [MRTest(2, 3, 5)]
    [MRTest(3, 4, 7)]
    public int TestMethod(int a, int b)
    {
        return a + b;
    }
}

为测试用例添加描述(CNTest和MNTest)

[CTest("这是一个测试类")]
public class TestClass
{
    [MNTest("这是一个测试方法")]
    public void TestMethod()
    {
        Console.WriteLine("Hello World!");
    }
}

同时添加描述和结果对比(MNRTest)

[CTest("这是一个测试类")]
public class TestClass
{
    [MNRTest("这是一个测试方法", 1, 2, 3)]
    public int TestMethod(int a, int b)
    {
        return a + b;
    }
}

设置测试类的初始化方法(SetUp)

[CTest]
public class TestClass
{
    string initWord;
    [SetUp]
    public void SetUp()
    {
        initWord = "Hello World!";
    }

    [MTest]
    public void TestMethod()
    {
        Console.WriteLine(initWord);
    }
}

直接测试静态方法(SMTest)

public class TestClass
{
    [SMTest]
    public static void TestMethod()
    {
        Console.WriteLine("Hello World!");
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.4 135 8/18/2024
2.0.3 126 4/16/2024
2.0.2 106 4/14/2024
2.0.1 129 3/20/2024
2.0.0 120 3/7/2024

更新引用包