You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if some of the samples had unit tests or there was a sample unit test project. It's good for people looking through the samples to see how to unit test it because putting off unit tests just leads to tech debt in the future.
Reacted by KamasamaK, Benjamin Lannon, Yu Zhang, Connor Shea, Simon Siefke, Lukas Spieß, Alexander, Joe Previte, Adam Bender and Andrey Rakhmatullin
I would be interested in making a PR for this given I've been writing a vscode extension and setting up some unit tests for it. Not sure what to test for an example but I am interested in helping out
It would also be useful to distinguish between unit tests and end-to-end/integration tests.
E2E tests are useful because they run on an actual VSCode instance, but they are too slow to be run often during development (e.g. on save).
The unit tests are very fast and suitable for immediate feedback during development (e.g. on save), but require mocking; especially the vscode parts, which is tricky until you figure it out the first time.
A person just asked about this in the vscode slack channel.
Anon1
guys what do you do about unit testing `vscode` ?
We’re currently writing stub methods for everything we use
that’s getting boring, real quick
Some responses:
Anon2
doing the same over here. it’s not too bad but maybe i’m not using as much of the API as you are. i’m also using sinon for the stubs.
Anon3
It depends on what code you're trying to write tests for. You're right in that if you want to do unit testing you'll end up writing stubs for vscode api's.
In my experience it's a case by case evaluation on which approach (unit vs integration) will provide you the most benefits.
In summary it seems like most people are in favor of mocking the actual VSCode API. This lets your tests run faster at the cost of the time it takes to make the mock.
Activity
lannonbr commentedon Sep 6, 2018
I would be interested in making a PR for this given I've been writing a vscode extension and setting up some unit tests for it. Not sure what to test for an example but I am interested in helping out
gkalpak commentedon Sep 10, 2018
It would also be useful to distinguish between unit tests and end-to-end/integration tests.
E2E tests are useful because they run on an actual VSCode instance, but they are too slow to be run often during development (e.g. on save).
The unit tests are very fast and suitable for immediate feedback during development (e.g. on save), but require mocking; especially the
vscodeparts, which is tricky until you figure it out the first time.FWIW, I am using mock-require for my setup. Here is my
vscodemock and here my overall test setup (which is a little involved, because I wanted to use jasmine 😁).Almenon commentedon Sep 18, 2018
I just updated my integration tests for the new webview API, the same format could be applied to the webview sample.
https://github.com/Almenon/AREPL-vscode/blob/master/test/suite/previewContainer.test.ts
The only catch is I had to make a mock context like so:
Aside from that it's just calling the function that updates the html and verifying that the expected output is in the html, pretty simple.
Almenon commentedon Dec 15, 2018
A person just asked about this in the vscode slack channel.
Some responses:
In summary it seems like most people are in favor of mocking the actual VSCode API. This lets your tests run faster at the cost of the time it takes to make the mock.
connor4312 commentedon Jul 14, 2021
Duplicates microsoft/vscode#94746
Almenon commentedon Jul 16, 2021
This issue is a subset of microsoft/vscode#94746, but not a duplicate. microsoft/vscode#94746 is asking for a mock library and general guidance. Can you reopen please?
connor4312 commentedon Jul 16, 2021
There is guidance given to mocking in the discussion on that issue, for example my comment here: microsoft/vscode#94746 (comment)
Almenon commentedon Jul 17, 2021
I appreciate the comment, but it's not the same as having multiple unit test examples to reference.