基数是什么意思| 牙齿发黄是什么原因| 紫色加红色是什么颜色| 白细胞酯酶阳性是什么意思| 孕妇胆固醇高对胎儿有什么影响| 解酒吃什么药| 白羊座和什么座最配| 巾帼不让须眉什么意思| 为什么今年有两个六月| 钙化积分是什么意思| 牛肉发绿色是什么原因| 心跳不规律是什么原因| ex是什么的缩写| 什么样的女人水多| 虎的本命佛是什么佛| 肌酐高可以吃什么水果| 儿童吃什么| 男性吃什么增强性功能| 凝血因子是什么| 身份证末尾x代表什么| 肝火旺盛是什么原因引起的| 脚为什么会脱皮| 发明什么| gv是什么意思| 梦到头发白了是什么意思| shipped是什么意思| 广西狗肉节是什么时候| 7.1是什么星座| 酵母样真菌是什么意思| 美业是做什么的| 什么是宫颈息肉| 中年危机是什么意思| 猪心炖什么适合孩子| 复方氨酚烷胺胶囊是什么药| 神经衰弱吃什么药效果最好| 洗白是什么意思| 流汗多是什么原因| 脸色发黄是什么原因| 便溏是什么原因引起的| a型血与o型血生的孩子是什么血型| 咳嗽脑袋疼是什么原因| 心肌缺血是什么原因引起的| 六味地黄丸什么功效| 什么的粉墙| 1946年属什么| 3.13是什么星座| 晚上一点多是什么时辰| 什么食物胶原蛋白含量高| 男女授受不亲是什么意思| 一个月一个屯念什么| 什么滔滔| 庶子是什么意思| 211985是什么意思| 极光是什么意思| 蒹葭苍苍是什么意思| 补铁吃什么食物好| 开眼镜店需要什么设备| 什么叫手淫| 笑是什么意思| 糖尿病人喝什么茶最好| 手发抖是什么病| 11度穿什么衣服| 神经痛吃什么药| 颈椎钙化是什么意思严重么| 儿化音是什么意思| 心脏不舒服挂什么科室| 右束支传导阻滞是什么意思| 勰读什么| MR医学上是什么意思| 这是什么情况| 心身医学科是看什么病| r是什么牌子衣服| 小孩内热吃什么药| 什么时候同房容易怀孕| 奶奶的弟弟叫什么| 瞧不起是什么意思| 反应性细胞改变炎症是什么意思| 肩周炎挂什么科| 天蝎座男生喜欢什么样的女生| 梦见骂人是什么意思| 什么凌乱| 儿童中暑吃什么药| 狗狗体内驱虫用什么药最好| 潜规则是什么| 冲太岁是什么意思| 吃什么可以提高免疫力| 地藏菩萨为什么不能拜| 什么是热伤风| 九寨沟在什么地方| 眼睛经常充血是什么原因引起的| 吃羊肉不能吃什么东西| 秋田狐鱼钩适合钓什么鱼| 木薯粉是什么粉| 包拯属什么生肖| 太爷爷的爸爸叫什么| 胃热吃什么| 坐骨神经痛挂什么科| 暴饮暴食会得什么病| 左耳烫代表什么预兆| 又当又立是什么意思| 摆拍是什么意思| 坚信的意思是什么| 白头发挂什么科| cn什么意思| 西洋参不适合什么人吃| 重度贫血是什么原因引起的| 发炎不能吃什么东西| 什么洗发水好用| 小孩割包皮挂什么科| 开天门是什么意思| 糖类抗原CA125高是什么意思| 胶原蛋白有什么作用| 待字闺中什么意思| 鸭梨是什么颜色| 阴血亏虚吃什么中成药| 如法炮制是什么意思| 吃什么最补血而且最快| 客家人为什么叫客家人| 男性尿路感染有什么症状| 驹是什么意思| 两个立念什么| 龟头有点痒擦什么药| 皮肤发痒用什么药| 肚脐眼疼是什么原因| 准奏是什么意思| 1999年出生的属什么| 什么是音程| svc是什么意思| 空调有异味是什么原因| 早上五点半是什么时辰| www是什么| 龙舌兰是什么酒| 低压高吃什么药好| 发现新大陆是什么意思| 甘露是什么| 什么是假性抑郁症| 高粱是什么| 男人梦见蛇是什么征兆| 什么是有机食品和无机食品| 牙周炎吃什么药好| 汤姆福特属于什么档次| 孔明属什么生肖| 吃什么凉血效果最好| 白鱼是什么鱼| 吃什么可以降血糖| 失聪是什么意思| 骨龄大于年龄意味着什么| 做梦牙掉了是什么征兆| 龙眼是什么季节的水果| 手麻脚麻吃什么药| 5个月宝宝可以吃什么水果| b型血和b型血生的孩子是什么血型| 复机是什么意思| 什么叫性生活| 间接胆红素偏高吃什么药| 端倪是什么意思| 鲫鱼吃什么| 嗓子不舒服做什么检查| omega3是什么意思| 什么情况会染上鼠疫| 淋巴结肿大看什么科| 小狗什么时候断奶| hyq什么意思| 出水芙蓉是什么意思| 5岁属什么生肖| 黑瞎子是什么动物| 汀是什么意思| 胰岛素抵抗是什么意思| 罗衣是什么意思| 虚情假意是什么意思| 神经性头疼吃什么药好| 痛风什么东西不可以吃| gmail是什么邮箱| 卡粉是什么原因引起的| 五味子有什么功效| 楞头青是什么意思| 爬山是什么意思| 鼓目念什么| 一什么野花| 胆汁酸高吃什么药| 月经推迟是什么原因导致的| 千千阙歌什么意思| 辅助什么意思| 晚上吃什么水果对身体好| 豆角炒什么| 属鸡的守护神是什么菩萨| 什么凝视| 梦见牛顶我是什么意思| 因果业力是什么意思| 夜盲症吃什么| 四五天不排便是什么原因| 辄是什么意思| 生命的真谛是什么| vcr是什么意思| 肝囊肿吃什么药能消除| 两个圈的皮带是什么牌子| 昆虫记是什么类型的书| 脚一直出汗是什么原因| pca是什么意思| 嘴唇发紫发黑是什么原因| 姜红枣红糖一起煮有什么效果| 7月18日是什么日子| 吃虾不能吃什么| 梦见种树是什么兆头| 人体最长的骨头是什么| 青花鱼是什么鱼| 什么的樱桃| cut什么意思| 干咳吃什么药效果好| 异性是什么意思| 老年人尿血是什么原因| 双非是什么意思| 宾馆和酒店有什么区别| 吃海鲜不能吃什么水果| 手术后可以吃什么| 胯疼是什么原因| 女人吃枸杞有什么好处| 什么东西解辣| 男人吃什么食物可以补肾壮阳| 碳酸钙d3片什么时候吃最好| 危险期是什么时候| 白浆是什么| mk属于什么档次| 反清复明的组织叫什么| 胃胀消化不好吃什么药| 什么饮料解酒| 早泄用什么药| 血沉偏高是什么原因| 血压低压高吃什么药| 睾丸疼痛吃什么药| 胎盘能治什么病| 邪气是什么意思| 四月份是什么季节| 美团外卖和美团有什么区别| 男人是什么| 僧侣是什么意思| 黄体生成素是什么| 非洲人一日三餐吃什么| 雌二醇e2是什么意思| cta是什么意思| 肠易激综合征是什么病| 木石念什么| 副总经理是什么级别| 考试前吃什么能让大脑发挥最佳| pouch什么意思| 梦到前男友是什么意思| 什么人不适合吃海参| 冰冻三尺非一日之寒什么意思| 我们在干什么| 鸡蛋价格为什么这么低| 什么是兼职| 专业术语是什么意思| 这是什么猫| 乳腺瘤不能吃什么| 做梦梦到蟒蛇是什么征兆| 声声慢是什么意思| 气血不足吃什么中药| 伪娘是什么意思| 心肌梗塞是什么原因造成的| 舌苔发黄什么原因| 张国荣为什么喜欢男的| 皮肤黑吃什么会变白| 物欲横流什么意思| 急性扁桃体炎什么原因导致的| 百度

Try to extend agent mode in VS Code!

香港嘉里酒店将于4月28日在维多利亚港海滨隆重开幕

百度 读中学读大学,读硕士读博士,读来读去,快读成烈士了,却还找不到工作。

Visual Studio Code provides a rich set of features for testing your code. You can automatically discover tests in your project, run and debug your tests, and get test coverage results. GitHub Copilot in VS Code can assist with setting up the testing framework for your project, and help you generate test code and fix failing tests.

In this article, you'll learn how to start with testing in VS Code, find popular testing extensions, and explore the testing features. You'll also learn how Copilot in VS Code can help you write tests faster and can assist you in fixing failing tests.

Tip

If you don't have a Copilot subscription yet, use Copilot for free by signing up for the Copilot Free plan. You'll get a monthly limit of completions and chat interactions.

About testing in VS Code

Testing support in VS Code is language-specific and depends on the testing extensions you have installed. Language extensions or standalone extensions can implement the testing features for a particular language or testing framework.

VS Code has the following features for testing your code:

  • Support multiple testing frameworks: language extensions and standalone testing extensions provide support for various languages and test runners, such as Jest, Mocha, Pytest, JUnit, and more.

  • Centralized test management: the Test Explorer provides a centralized place to manage and run the tests in your project. The Test Explorer might automatically discover the tests in your project, depending on the testing extension.

  • Integrated test results: view the test status inline in the editor alongside the test code, or view all tests in the Test Explorer. Detailed test results are available in the Test Results panel.

  • Debugging: debug your tests to diagnose test failures. Take advantage of the rich debugging support in VS Code, such as breakpoints, watch variables, and more.

  • Test coverage: run tests with coverage to see how much of your code is covered by your tests.

  • AI-assisted testing: use GitHub Copilot in VS Code to assist you with setting up your testing framework, generating test code, and fixing failing tests.

  • Task integration: make your testing work easier by creating tasks to run your tests. You can also run your tests in the background when you change your code.

Get started with testing in VS Code

To get started with testing in VS Code, follow these steps:

  1. Open the Extensions view and install a testing extension for your project. Filter the extensions by the Testing category (@category:"testing").

  2. Select the beaker icon () in the Activity Bar to open the Test Explorer and discover the tests in your project.

  3. Run and debug your tests from the Test Explorer or directly from the editor.

Extensions for testing

You can find extensions that support testing by looking in the Visual Studio Marketplace. You can also go to the Extensions view (??X (Windows, Linux Ctrl+Shift+X)), and filter by the Testing category.

Tip

Copilot can assist with setting up a testing framework and suggesting relevant testing extensions. Open the Chat view (??I (Windows, Linux Ctrl+Alt+I)), enter the /setupTests command, and Copilot will guide you through the process of configuring your project.

Automatic test discovery in Testing view

The Testing view provides a centralized place to manage and run your tests. You can get to the Testing view by selecting the beaker icon () in the Activity Bar. You can also use the Testing: Focus on Test Explorer View command in the Command Palette (??P (Windows, Linux Ctrl+Shift+P)).

If you have a project with tests, the Test Explorer view discovers and lists the tests in your workspace. By default, the discovered tests are displayed in a tree view in the Test Explorer. The tree view matches the hierarchical structure of your tests, making it easy to navigate and run your tests.

Screenshot that shows VS Code with the Test Explorer showing the tests, matching the test code that is shown in the editor.

You can run tests from the Test Explorer by selecting the play button. Learn more about running and debugging tests in the Run and debug tests section.

Tip

Navigate to the test code by double-clicking on the test in the Test Explorer view. If you select a test that failed, the editor opens the test file, highlights the failed test, and shows the error message.

If you have many tests, you can use the filtering options to quickly find the tests you're interested in. You can use the Filter button to filter tests by status or only show tests for the current file. You can also use the search box to search for specific tests by name or use the @ symbol to search by status.

Test Explorer view with filtering options

In the More Actions menu, you can access more functionality, such as sort and display options.

If you add new tests or change your tests, use the Refresh Tests button to refresh the list of tests in the Test Explorer. You can also use the Test Explorer: Reload tests command in the Command Palette (??P (Windows, Linux Ctrl+Shift+P)).

Note

Depending on the testing extension, you might first have to configure the test framework or test runner to discover the tests in your project. For more information, consult the documentation of the testing extension. You can use the setupTests command in Copilot Chat view to get help with setting up a testing framework for your project.

Write tests with AI

Writing tests can be time-consuming and they're often neglected. Copilot can speed up the process of writing tests by creating test code for your application. You can use it to write unit tests, integration tests, end-to-end tests, and more.

To write tests with Copilot in VS Code, you can use either of these methods:

  • Editor smart actions

    1. Optionally, select a block of application code

    2. Right-click in the editor, and then select Copilot > Generate Tests

  • Chat prompts

    1. Open the application code file for which you want to generate tests

    2. Open the Copilot Edits (), the Chat view (??I (Windows, Linux Ctrl+Alt+I)), or the editor Inline Chat (?I (Windows, Linux Ctrl+I))

    3. Enter a prompt to generate tests, such as Generate tests for this code. Also include tests for edge cases.

      Add extra context to your prompt by typing #file in the prompt. For example, Generate tests for this code #file:calculator.js

      Tip

      Get more example prompts for generating unit tests, mock objects, or end-to-end tests in the GitHub Copilot documentation.

Copilot will generate test cases code for your application code. If you already have a tests file, Copilot will add the tests there, or create a new file, if needed. You can further customize the generated tests by providing more prompts to Copilot. For example, you can ask Copilot to use another testing framework.

Tip

You can give Copilot your own special instructions for generating code. For example, you can tell Copilot to use a certain testing framework, naming convention, or code structure.

Learn more about using Copilot in VS Code.

Run and debug tests

After the discovery of the tests in your project, you can run and debug your tests, and view test results directly from within VS Code.

In the Test Explorer, use the controls in the section heading to run or debug all tests. You can also run or debug specific tests in the tree view by selecting the run/debug icon on a specific node.

Run and debug tests in Test Explorer

As you're viewing the test code in the editor, use the play control in the editor gutter to run the test at that position.

Run and debug tests in editor gutter

Right-click on the gutter control to view other actions, such as debugging the test.

Tip

Configure the default testing action for the gutter control by using the testing.defaultGutterClickAction setting.

After you run one or more tests, the editor gutter and tree view in the Test Explorer display the corresponding test status (passed/failed). When a test fails, notice that the test error message is shown as an overlay in the editor.

Screenshot that shows a test error message overlay in the editor.

Use the Show Output button in the Test Explorer to view the test output in the Test Results panel.

Test Results panel

Tip

Copilot can help you fix failing tests. In the Test Explorer, hover over the tree view, and select the Fix Test Failure button (sparkle) and Copilot will suggest a fix for the failing test. Alternatively, enter the /fixTestFailure command in Copilot Chat.

Screenshot showing the Test Explorer, highlighting the "Fix Test Failure" button, and the editor that shows a suggestion from Copilot on how to fix the failing test.

Test coverage

Test coverage is a measure of how much of your code is covered by your tests. It helps you identify areas of your code that are not being tested. VS Code supports running tests with coverage and viewing the coverage results if the corresponding testing extension support test coverage.

You can run tests with coverage, just like you can run and debug tests. Use corresponding the actions in the Test Explorer view, editor gutter, or commands in the Command Palette (??P (Windows, Linux Ctrl+Shift+P)).

Run tests with coverage

After you run tests with coverage, you can view the coverage results in different locations:

  • In the Test Coverage view

    A tree view shows the tests with their coverage percentage. A color indicator also gives a visual cue about the coverage percentage. Hover over each line to see more details about the coverage results.

    Test Coverage view

  • As an overlay in the editor

    For code files that have test coverage, the editor shows a color overlay in the gutter to indicate which lines are covered by tests or not. When you hover over the gutter, notice that for covered lines, there is also an indicator for the number of times the line was executed. You can also select the Show Inline Coverage button in the editor title bar or use the Test: Show Inline Coverage command (?; ??I (Windows, Linux Ctrl+; Ctrl+Shift+I)) to toggle the coverage overlay.

    View coverage in editor

  • In the Explorer view, which shows the coverage percentage of your code files

    The Explorer view shows the coverage percentage of your code files. Hover over a file or node in the Explorer to see more details about the coverage results.

    View coverage in Explorer view

  • In the diff editor

    If you have a diff editor open, the coverage results are also shown in the diff editor, similar to how they're shown in the editor.

Task integration

Tasks in VS Code can be configured to run scripts and start processes within VS Code, without having to enter a command line or write new code. In VS Code, you can define a default test task that runs your tests, and optionally create keyboard shortcuts to run the tests.

Use the command Tasks: Configure Default Test Task to configure the default test task. VS Code tries to automatically detect the test task, for example based on your package.json file. After you select the default test task, the tasks.json file is opened for you to customize the task.

The following code snippet shows a tasks.json file that specifies the node --test command as the default test task.

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "npm",
      "script": "test",
      "group": {
        "kind": "test",
        "isDefault": true
      },
      "problemMatcher": [],
      "label": "npm: test",
      "detail": "node --test src/tests/**.js"
    }
  ]
}

To run the test task, use the command Tasks: Run Test Task or create a keyboard shortcut for the command.

Learn more about using and configuring Tasks.

Note

Currently, tasks don't have special integration into VS Code's testing functionality, so running tests in a task won't update the user interface. Individual testing extensions can provide specific test automation functionality that integrates in the UI.

Test configuration settings

There are multiple settings that you can configure to customize the testing experience in VS Code. Each language extension might provide additional settings specific to testing in that language. Here are some common settings that you can configure:

Setting ID Details
testing.countBadge Controls the count badge on the Testing icon on the Activity Bar
testing.gutterEnabled Configure whether to show the test control in the editor gutter
testing.defaultGutterClickAction Configure the default action when selecting the gutter test control
testing.coverageBarThresholds Configure the colors for the coverage bar thresholds for the Test Coverage view
testing.displayedCoveragePercent Configure what percentage value is displayed in the Test Coverage view (total, statement, or minimum)
testing.showCoverageInExplorer Configure whether to show the coverage percentage in the Explorer view

You can find all testing-related settings in the Settings editor (?, (Windows, Linux Ctrl+,)).

Next steps

电脑什么时候发明的 田反念什么 检查幽门螺杆菌挂什么科 韭菜可以炒什么 甘草配什么泡水喝最好
孟子姓什么 善待是什么意思 胃左边疼是什么原因 什么是招风耳图片 中国最大的海是什么海
牙痛用什么止痛 现在什么冰箱最好 梦见长大水是什么意思 枯木逢春是什么意思 女人有卧蚕代表什么
月经咖啡色是什么原因 perry是什么意思 xxoo什么意思 梦见种地是什么意思 一个h是什么牌子
手腕痛是什么原因bjcbxg.com 什么是交感神经hcv9jop5ns3r.cn 蚁后长什么样hcv7jop9ns7r.cn 心气虚吃什么中成药hcv8jop6ns7r.cn 淡然自若的意思是什么ff14chat.com
心率过低吃什么药hcv9jop6ns6r.cn 红薯什么时候掐尖hcv9jop1ns6r.cn 农历十月初五是什么星座96micro.com gy是什么意思hcv7jop6ns1r.cn 什么是淋病hcv8jop8ns1r.cn
肾囊肿有什么症状表现hcv9jop5ns0r.cn 吉利丁片是什么hcv7jop9ns8r.cn 826是什么意思hcv7jop9ns6r.cn 化痰止咳吃什么药最好hcv8jop3ns0r.cn 房间放什么可以驱蜈蚣hcv9jop0ns1r.cn
喉咙发炎吃什么药最好hcv8jop9ns0r.cn 人瘦是什么原因造成的hcv8jop7ns6r.cn 翻版是什么意思hcv7jop9ns8r.cn 税号是什么hcv8jop0ns2r.cn 牛肉和什么包饺子好吃hcv8jop1ns3r.cn
百度