Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more unit tests #1144

Open
1 of 5 tasks
tanishiking opened this issue Sep 1, 2022 · 0 comments
Open
1 of 5 tasks

Add more unit tests #1144

tanishiking opened this issue Sep 1, 2022 · 0 comments

Comments

@tanishiking
Copy link
Member

tanishiking commented Sep 1, 2022

Describe the problem

Even though metals-vscode has many advanced features (such as checking for updates, installing java, showing release notes, etc.), there are quite a small number of unit/integration tests.

Therefore, when we update the features of metals-vscode, we usually "test" the extension by hand. However, testing by hand leaves a lot of anxiety for release. (What if some features are broken without notice?)

I propose adding some unit tests to the extension to remove the anxieties. (It would be best if we could test all the features with integration tests, but it requires too much, let's start with unit testing).


Which features to unit test?
In unit tests, we should focus on the logic that can be independent of vscode APIs.

  • check for updates on the Metals server
    • needCheckForUpdates
    • validateCurrentVersion
  • releaseNoteProvider
  • installJavaAction

I guess other features can be tested by integration tests.


For writing unit tests
As described in microsoft/vscode#82471

The vscode-test package allows you to run integration tests where you launch the tests through vscode and a instance of vscode opens up. But if I want to do normal unit tests against code that has even a single reference to vscode I am not able to do so due to microsoft/vscode#6586.

to run unit tests, we should extract the logic that doesn't depend on vscode API by abstracting out the dependencies.

In order to do this, I would propose adding some layers to the project structures.

  • application layer: this layer is basically referred from extension.ts
    • can access vscode APIs (executing command, setting up repositorys for service layer using VSCode APIs.
  • service layer: this layer contains the business logic that doesn't rely on vscode APIs, we will unit test against this layer.
  • repository layer: this layer contains the logic that
    • access to vscode APIs (such as reading and updating configurations)
    • access to external APIs (HTTP)
src
|-- installJavaAction.ts (application layer)
|-- service
|   `-- CheckForUpdateService.ts
|-- repository
|   `-- CheckForUpdateRepo.ts

Here's a POC implementation for unit testing needCheckForUpdate tanishiking#82

Additional context

Search terms

unit test

tanishiking added a commit to tanishiking/metals-vscode that referenced this issue Sep 2, 2022
scalameta#1144

This commit adds a test for `needCheckForUpdates`.

For adding unit tests, this commit abstract away the logic that needs
access to vscode APIs, becuase we need to run an integration test for
accessing vscode APIs.
see: microsoft/vscode-wordcount#5 (comment)
microsoft/vscode#82471 (comment)
tanishiking added a commit to tanishiking/metals-vscode that referenced this issue Sep 2, 2022
scalameta#1144

This commit adds a test for `needCheckForUpdates`.

For adding unit tests, this commit abstract away the logic that needs
access to vscode APIs, becuase we need to run an integration test for
accessing vscode APIs.
see: microsoft/vscode-wordcount#5 (comment)
microsoft/vscode#82471 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant