Testing in VS Code
Problem
State of the World Testing support in VS Code has been a feature request for a long time. The VS Code community has build excellent extensions around testing, for example: - The Test Explorer UI from @hbenl - Wallaby.js from the Wallaby team - Jest from @orta - ...and many more Each implementation of testing presents a different set of features, UI, and idiomaticity. Because there is no sanctioned approach to tests in VS Code, extension developers tend to make bespoke implementations, as we've seen in the Python and Java language extensions. Ideally, like in debugging, a VS Code user would have just about the same experience as they work between projects and languages. VS Code's Approach > Investigate how VS Code can improve the testing support. Several extensions are already providing testing support, explore what APIs/UIs could be added to improve these testing extensions and the test running experience. -- 2020 Roadmap The Test Explorer UI presents the best point of inspiration for us, as there are many existing extensions built on its API: it's capable and proven. Regardless of the direction we take in VS Code, we should have a way for its Test Adapters to be upgraded to the new world. Wallaby is an excellent extension, but it's tailored and purpose-built to JavaScript, and includes functionality which is not readily portable to other languages. While it is a good source for inspiration, we're not aiming to encompass Wallaby's feature set in the extension points we
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Standardize Testing API in VS Code
The lack of a unified testing API in VS Code leads to fragmented testing experiences across different languages and extensions. Each extension implements its own approach, resulting in inconsistencies in user experience and functionality.
Awaiting Verification
Be the first to verify this fix
- 1
Define a Unified Testing API
Create a standardized API for testing extensions that can be used across different languages. This API should include common functionalities such as test discovery, execution, and reporting.
typescriptinterface TestAdapter { discoverTests(): Promise<Test[]>; runTests(tests: Test[]): Promise<TestResult[]>; onTestRunFinished(callback: (results: TestResult[]) => void): void; } - 2
Implement Test Explorer Integration
Ensure that the new testing API integrates seamlessly with the existing Test Explorer UI. This will allow users to view and interact with tests in a consistent manner across different projects and languages.
typescript// Example of integrating with Test Explorer const testAdapter: TestAdapter = new MyTestAdapter(); testAdapter.onTestRunFinished((results) => { TestExplorer.update(results); }); - 3
Create Documentation and Examples
Develop comprehensive documentation and examples for extension developers on how to use the new testing API. This will encourage adoption and ensure that extensions are built consistently.
javascript// Example documentation snippet /** * @function discoverTests * @description Discovers all tests in the project. * @returns {Promise<Test[]>} A promise that resolves with an array of Test objects. */ function discoverTests() { /* implementation */ } - 4
Gather Feedback from Extension Developers
Engage with the community of extension developers to gather feedback on the new API and make iterative improvements based on their input. This will help ensure that the API meets the needs of a diverse set of languages and testing frameworks.
javascript// Example of a feedback form link const feedbackFormUrl = 'https://example.com/feedback'; console.log(`Please provide your feedback: ${feedbackFormUrl}`);
Validation
Confirm that the new testing API is being used by at least three existing testing extensions and that they provide a consistent user experience in the Test Explorer. Additionally, gather user feedback to ensure satisfaction with the new implementation.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep