How to Use GitHub Copilot With VS Code Test Explorer for Test Discovery
🔍 WiseChecker

How to Use GitHub Copilot With VS Code Test Explorer for Test Discovery

You want to run your unit tests quickly without manually configuring every test framework in VS Code. The Test Explorer sidebar can discover and execute tests automatically, but setting it up for complex projects often requires editing launch.json or tasks.json files. This article shows how GitHub Copilot can generate the correct test configuration for your project so Test Explorer detects your tests immediately.

Test Explorer relies on VS Code extension settings and framework-specific adapters to find test files. When Copilot generates these settings, it reads your project structure and suggests the right adapter paths, test file patterns, and environment variables. You will learn the exact steps to prompt Copilot inside VS Code, apply the generated configuration, and verify that Test Explorer lists all your test cases.

By the end of this guide, you can set up test discovery for any language or framework without manual trial and error. You will also know how to handle edge cases like monorepos and mixed-language projects.

Key Takeaways: Using Copilot to Configure Test Explorer

  • Copilot Chat > /fix or /configure: Use these slash commands to generate test adapter settings for your project language.
  • settings.json > testExplorer.useNativeTesting: Toggle this to enable native test discovery without third-party extensions.
  • Test Explorer sidebar > gear icon: Opens the configuration file where Copilot inserts the generated code.

ADVERTISEMENT

How Test Explorer Discovers Tests and Why Copilot Helps

The VS Code Test Explorer sidebar does not scan your project by default. It relies on a test adapter extension that knows how to parse your test framework. For example, the Python Test Explorer extension looks for files named test_py or _test.py and runs pytest or unittest. The adapter settings live in your workspace .vscode/settings.json file.

When you work with multiple test frameworks or a monorepo, the configuration becomes complex. You must specify the correct test framework path, environment variables, and file exclusion patterns. Copilot can inspect your project structure and suggest the exact JSON or YAML settings needed. It uses the same logic a human developer would apply, but it completes the task in seconds.

Copilot also helps when you switch between projects. Instead of remembering the exact adapter syntax for Jest, Mocha, PyTest, or NUnit, you describe your project in plain English and Copilot writes the configuration. This reduces setup time and eliminates syntax errors that prevent test discovery.

Steps to Configure Test Explorer With Copilot

Follow these steps to let Copilot generate the test adapter settings for your project. The process works for JavaScript, Python, C#, Java, and most other languages supported by VS Code test adapters.

  1. Open the Copilot Chat panel
    Press Ctrl+Shift+I on Windows or Cmd+Shift+I on macOS to open Copilot Chat. If you use the inline chat, press Ctrl+I or Cmd+I inside the settings.json file.
  2. Describe your project and test framework
    Type a prompt such as: Configure test explorer for a Python project using pytest. Tests are in the tests/ folder. Use unittest as the fallback. Copilot will generate the required JSON settings for your workspace.
  3. Review the generated settings
    Copilot outputs JSON code. Look for python.testing.pytestEnabled, python.testing.unittestEnabled, and python.testing.cwd. Verify the paths match your project structure.
  4. Apply the settings to your workspace
    Click the Insert into settings.json button that appears in the Copilot Chat response. If the button does not appear, copy the code manually and paste it into .vscode/settings.json.
  5. Reload the Test Explorer sidebar
    Click the Reload icon in the Test Explorer sidebar toolbar or press Ctrl+Shift+P and run Developer: Reload Window. The sidebar should now show your test files and test cases.
  6. Run a test to confirm discovery
    Click the play icon next to any test in the Test Explorer. If the test passes, the configuration is correct. If the test fails with a framework error, check the adapter version and the test file paths.

Using Copilot for a JavaScript Project With Jest

For a JavaScript or TypeScript project using Jest, prompt Copilot with: Set up Jest test discovery in VS Code. Tests are in src/__tests__/ and use the .test.js extension. Copilot will generate settings that enable the Jest Test Explorer extension and set the test file pattern. Apply the settings to .vscode/settings.json and reload the Test Explorer.

Using Copilot for a C# Project With NUnit

For .NET projects using NUnit, prompt Copilot with: Configure .NET test adapter for NUnit. The project is in the src/MyProject.Tests folder. Use dotnet test. Copilot may suggest adding the .vscode/tasks.json configuration for dotnet test and the csharp.testExplorer.nunit.enabled setting. Insert the code and reload the workspace.

ADVERTISEMENT

Common Issues When Copilot Generates Test Configuration

Even with Copilot, you may encounter problems that prevent test discovery. The most frequent issues involve missing extensions, incorrect file patterns, or environment variables that Copilot cannot infer. Below are the most common problems and their fixes.

Test Explorer Shows No Tests After Configuration

This usually means the test adapter extension is not installed or the file pattern does not match. First, install the correct test adapter for your language. For Python, install Python Test Explorer for Visual Studio Code. For JavaScript, install Jest Test Explorer or Mocha Test Explorer. Then verify the generated file pattern. Copilot may use a pattern like /test_py but your files might use a different naming convention. Edit the pattern manually in settings.json to match your files.

Copilot Generates Settings for the Wrong Framework

If your project uses multiple test frameworks, Copilot might guess the wrong one. Be explicit in your prompt. For example, say Use pytest only, not unittest or Configure Jest, not Mocha. If the generated settings still contain the wrong framework, delete the incorrect keys and ask Copilot to regenerate with a more specific prompt.

Environment Variables Not Set Correctly

Some test frameworks require environment variables to find test databases or API endpoints. Copilot cannot see your system environment variables. After Copilot generates the configuration, open .vscode/launch.json and add an env block with the required variables. For example, add "env": {"DATABASE_URL": "localhost:5432/testdb"}.

Copilot Chat vs Inline Copilot for Test Configuration

Item Copilot Chat Inline Copilot
Access method Ctrl+Shift+I or Cmd+Shift+I Ctrl+I or Cmd+I inside a file
Best for Generating full configuration blocks from scratch Editing small sections of existing settings.json
Output format Full JSON or YAML with Insert button Single line or short snippet
Context awareness Reads entire workspace structure Reads only the open file and cursor position
Reliability for multi-framework projects High, because it sees all files in the workspace Medium, because it may miss files not referenced in the open file

Use Copilot Chat when you need a complete configuration for a new project. Use inline Copilot when you need to tweak an existing pattern or add one missing setting.

Conclusion

You can now set up VS Code Test Explorer test discovery using Copilot-generated configuration for any supported framework. The key is to describe your project structure and test framework clearly in the Copilot Chat prompt. After applying the settings, always reload the window and run one test to confirm discovery works.

For monorepo projects, try prompting Copilot with Configure test explorer for a monorepo with Python tests in packages/backend/tests and JavaScript tests in packages/frontend/__tests__. Copilot will generate separate adapter settings for each subfolder. This approach saves hours of manual configuration when you work with large codebases.

ADVERTISEMENT