Skip to content
.NET 开发者指北.NET 开发者指北
CMS
.NET指北
FreeKit
Docker
关于
博客
github icon

.NET Core 简单测试项目

calendar icon2020年2月28日timer icon大约 2 分钟word icon约 488 字

此页内容
  • 源码
  • 相关参考

# .NET Core 简单测试项目

使用PowerShell的dotnet cli命令行创建控制台项目,测试项目,测试项目引用控制台项目。

# 源码

代码托管在GitHub上 https://github.com/luoyunchong/dotnetcore-examples/tree/master/console-news-typesopen in new window

# 相关参考

code :https://github.com/dotnet/samples/blob/master/core/console-apps/NewTypesMsBuild/README.mdopen in new window

docs: https://docs.microsoft.com/zh-cn/dotnet/core/tutorials/testing-with-cliopen in new window

dotnet-add-reference 使用文档 https://docs.microsoft.com/zh-cn/dotnet/core/tools/dotnet-add-referenceopen in new window

总结如下命令行

PS dotnetcore-examples> mkdir console-news-types
PS dotnetcore-examples> cd .\console-news-types\ 
PS dotnetcore-examples\console-news-types> mkdir src

PS dotnetcore-examples\console-news-types> mkdir test
PS dotnetcore-examples\console-news-types> ls
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----           2019/6/27    20:51                src
d----           2019/6/27    20:51                test

PS dotnetcore-examples\console-news-types> cd .\src\
PS dotnetcore-examples\console-news-types\src> dotnet new console -n NewTypes
PS dotnetcore-examples\console-news-types\src> cd ..\test\  
PS dotnetcore-examples\console-news-types\test> dotnet new xunit -n NewTypesTests 
PS dotnetcore-examples\console-news-types\test> cd .\NewTypesTests\
PS dotnetcore-examples\console-news-types\test\NewTypesTests> dotnet add reference ../../src/NewTypes/NewTypes.csproj
#Reference `..\..\src\NewTypes\NewTypes.csproj` added to the project.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

其他的代码就看上面的二个链接,把代码复制进去,代码很简单,一个接口,二个实现,main函数调用,测试项目引用控制台项目,

先cd 到src\NewTypes目录中,执行 dotnet run

PS dotnetcore-examples\console-news-types\src\NewTypes> dotnet run
Woof!
Meow!
1
2
3

先cd 到test\NewTypesTests目录中,执行 dotnet test,看好代码,测试类 Assert.Equal() 是成功的,如果是Assert.NotEqual() 则Failure

PS dotnetcore-examples\console-news-types\test\NewTypesTests> dotnet test
dotnetcore-examples\console-news-types\test\NewTypesTests\bin\Debug\netcoreapp3.0\NewTypesTests.dll 的测试运行(.NETCoreApp,Version=v3.0)
Microsoft (R) 测试执行命令行工具版本 16.0.1
版权所有 (C) Microsoft Corporation。保留所有权利。

正在启动测试执行,请稍候...

总测试: 2。已通过: 2。失败: 0。已跳过: 0。
测试运行成功。
测试执行时间: 1.5134 秒
1
2
3
4
5
6
7
8
9
10
edit icon在 GitHub 上编辑此页open in new window
上次编辑于: 2020/2/28 11:10:31
贡献者: luoyunchong
MIT Licensed | Copyright © 2021-present luoyunchong
苏ICP备16046457号-1

该应用可以安装在你的 PC 或移动设备上。这将使该 Web 应用程序外观和行为与其他应用程序相同。它将在出现在应用程序列表中,并可以固定到主屏幕,开始菜单或任务栏。此 Web 应用程序还将能够与其他应用程序和你的操作系统安全地进行交互。

详情