我使用 dotnet new react
创建了一个新的ASP.NET Core React应用程序。然后我添加了一些Jest单元测试,当我在命令行上运行 npm test
时,测试可以很好地运行。
我想能够从Visual Studio 2019中运行这些测试,无论是使用Test Explorer窗口还是ReSharper。
首先,似乎ReSharper只支持Jasmine而不是Jest(ReSharper文档,功能请求)。
因此,我尝试使用Test Explorer,遵循官方指南。它支持Jest。但是,ASP.NET Core的React模板不是一个node.js项目,因此测试框架和其他选项都不可用。因此,Test Explorer找不到任何测试。
然后我尝试使用命令 vstest.console.exe MyProject.csproj / TestAdapterPath:“C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Professional \ Common7 \ IDE \ Extensions \ Microsoft \ NodeJsTools \ TestAdapter”
运行测试。输出结果让我有些希望:
Microsoft (R) Test Execution Command Line Tool Version 16.5.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
No test is available in MyProject.csproj. Make sure that test
discoverer & executors are registered and platform & framework version settings are appropriate and
try again.
测试运行器至少找到了一个测试文件(实际上我有两个),但它不知道应该使用Jest 执行程序。我可以在 .csproj 文件中添加一些内容让它起作用吗?