XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.XUnit

【DLL】提供方便快捷的测试,无需编写Main方法,可直接添加特性在类或方法上进行测试

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension.NetCore.XUnit

更新README文件

a8814cd
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

3 个文件 +52 -9
Modified README.md +49 -1
@@ -1 +1,49 @@
1 # XFE各类拓展.NetCore.XUnit
1 # XFE各类拓展.NetCore.XUnit
2
3 ## 描述
4
5 XUnit测试框架,使得用户不需要编写Main函数,只需要在需要测试的类或者方法上面加上相对于的特性即可。
6
7 ## 示例
8
9 #### 快速编写无参测试用例
10
11 ```csharp
12 using System;
13 using XFE各类拓展.NetCore.XUnit;
14
15 [CTest]
16 //[CTest]
17 //可添加多个测试用例
18 public class TestClass
19 {
20 [MTest]
21 //[MTest]
22 //[MTest]
23 //可添加多个测试用例
24 public void TestMethod()
25 {
26 Console.WriteLine("Hello World!");
27 }
28 }
29 ```
30
31 #### 带参数的测试用例
32
33 ```csharp
34 using System;
35 using XFE各类拓展.NetCore.XUnit;
36
37 [CTest]
38 public class TestClass
39 {
40 [MTest]
41 [MTest(1, 2)]
42 [MTest(2, 3)]
43 [MTest(3, 4)]
44 public void TestMethod(int a, int b)
45 {
46 Console.WriteLine(a + b);
47 }
48 }
49 ```
Modified XFE各类拓展.NetCore.XUnit.Analyzer/XUnitCodeGenerator.cs +1 -7
@@ -11,14 +11,10 @@ namespace XFE各类拓展.NetCore.XUnit
11 11
12 12 public void Execute(GeneratorExecutionContext context)
13 13 {
14 // find the main method
15 var mainMethod = context.Compilation.GetEntryPoint(context.CancellationToken);
16
17 // build up the source code
18 14 string source = $@"
19 15 using XFE各类拓展.NetCore.XUnit;
20 16
21 namespace {mainMethod.ContainingNamespace.Name}
17 namespace XFE各类拓展.NetCore.XUnit
22 18 {{
23 19 public static class XUnitCode
24 20 {{
@@ -29,8 +25,6 @@ namespace {mainMethod.ContainingNamespace.Name}
29 25 }}
30 26 }}
31 27 ";
32 //var typeName = mainMethod.ContainingType.Name;
33 // add the source code to the compilation
34 28 context.AddSource($"XUnitCode.g.cs", source);
35 29 }
36 30 }
Modified XFE各类拓展.NetCore.XUnit/XFE各类拓展.NetCore.XUnit.csproj +2 -1
@@ -14,6 +14,7 @@
14 14 <PackageReadmeFile>README.md</PackageReadmeFile>
15 15 <RepositoryUrl>https://github.com/XFEstudio/XFEExtension.NetCore.XUnit</RepositoryUrl>
16 16 <PackageTags>Test;XUnit;XFE;Unit</PackageTags>
17 <Version>1.0.2</Version>
17 18 </PropertyGroup>
18 19
19 20 <ItemGroup>
@@ -30,7 +31,7 @@
30 31 </ItemGroup>
31 32
32 33 <ItemGroup>
33 <PackageReference Include="XFE各类拓展.NetCore" Version="1.5.0" />
34 <PackageReference Include="XFE各类拓展.NetCore" Version="1.5.1" />
34 35 </ItemGroup>
35 36
36 37 </Project>