-
Notifications
You must be signed in to change notification settings - Fork 59
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
Sample integration test could use more substance to it #160
Comments
A more complete example would probably better live in https://github.com/microsoft/vscode-extension-samples |
@connor4312 In extension.ts, change the HelloWorld callback function to:
Next, in package.json, add the command to the explorer context:
Next, in extension.test.ts, change
After compiling...
The debugger should break into the callback for the
In this case, the arguments being passed to the command are being constructed in the test itself, not in VS Code, thus hiding any bugs that might come up. re. 2: Thanks! I'll check out vscode-extension-tester re. residing in https://github.com/microsoft/vscode-extension-samples: Maybe... it looks like Well, regardless, I think adding some "real world"-like examples either here or to vscode-extension-samples (and the boilerplate code that gets generated when running |
In steps 1-4, the command is being triggered from the context menu in the explorer view. When called in this way, certain arguments are being passed to a command. However, commands can be called from anywhere, even multiple places in the VS Code UI (depending on its package contributions) or other extensions (if they use executeCommand.) If called from other places, they can receive different arguments. Commands are "public functions" and VS Code doesn't enforce a single schema for any given command's arguments. |
While the sample integration test does a great job of demonstrating how to set up the downloading of VS Code and setting up running the tests within VS Code, the integration test (
https://github.com/microsoft/vscode-test/blob/main/sample/test/suite/extension.test.ts
) which tests the sample extension (https://github.com/microsoft/vscode-test/blob/main/sample/src/extension.ts
) doesn't have much substance to it - it validates thatarray.indexOf()
returns -1, which doesn't really have much to do with validating the extension, and doesn't demonstrate how to drive the UI, and check & validate the state/contents of the UI after the test finished.It would be very helpful if there were examples demonstrating how to implement integration tests (end-to-end/integration tests, not unit tests), and show how to drive the UI, and test/validate the UI for expected results.
Now, one might say, "it's easy, just..."
vscode.commands.executeCommand('helloworld.helloWorld')
to the testvscode.window.showInformationMessage()
is called, and that it's called with "Hello World!"This has some shortcomings:
Directly calling
executeCommand()
and passing mocked data (the "rest" parameter) which we mock ourselves is not adequate. We recently found a bug where VS Code passes bad data to commands. (see sourceUri passed into commands is stale and out of date after file has been renamed vscode#152993). Microsoft says it's not a bug, but it is for us - when we're passed an incorrect file path, a library we depend on fails, so we wrote code to get around this and we need to write tests which automate this end to end.For this reason, we want to issue an instruction to VS Code itself, and tell VS Code to "run the "ABC" command", and not directly call
executeCommand()
We need to be able to drive the UI, and the driving needs to be performed at a high level - as if the user was typing themselves, and not programmatically by calling APIs or functions directly. Suppose our extension presents the user with a text prompt when the extension's command is invoked, and the user is prompted to enter in a string. We need to be able to write a test which waits for the text input prompt to appear, and then enter/input some text. Now suppose that when the command is invoked, that the user is prompted for input several times (to input several different values). We don't want to stub functions - we have a goal to make our integration tests be end-to-end, and be as if the user was inputing the data themselves, so this means no mocks/stubs.
What we want to do might not be aligned with how you intended integration tests to work, but...
Thanks,
Jeff
The text was updated successfully, but these errors were encountered: