【发布时间】:2020-09-25 20:52:33
【问题描述】:
我使用dotnet new react 创建了一个新的 ASP.NET Core React 应用程序。然后我添加了一些 Jest 单元测试,当我在命令行上运行 npm test 时,它们运行良好。
我希望能够使用测试资源管理器窗口或 ReSharper 从 Visual Studio 2019 运行测试。
首先,ReSharper 似乎只支持 Jasmine,不支持 Jest(ReSharper documentation,Feature request)。
所以我尝试使用测试资源管理器,遵循this official guide。它支持 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.
测试运行器找到至少一个测试文件(实际上我有 2 个),但它不知道它应该使用 Jest 执行器。我可以在 .csproj 文件中添加一些内容以使其工作吗?
【问题讨论】:
-
你找到解决办法了吗?
-
不,我什么都没有。我现在只是使用命令行。
标签: reactjs visual-studio unit-testing asp.net-core jestjs