Skip to content

Commit b473625

Browse files
authored
Add integration tests for TestExplorer (#806)
* Add integration tests for TestExplorer Add some integration tests that exercise finding and running tests, ensuring they complete with the expected outcome. It currently tests both normal test execution as well as debugging the tests. This patch adds a new profile used when running the tests locally via the Extension Tests task. This ensures that the workspace is always in a clean and consistent state. It adds some caps to the docker containers so we can run the debugger in tests. It also cleans up the test logs, silencing some harmless warnings.
1 parent 59eed1d commit b473625

26 files changed

+565
-111
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
out
22
dist
33
node_modules
4+
default.profraw
45
*.vsix
56
.vscode-test
67
.build

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
"type": "extensionHost",
2626
"request": "launch",
2727
"args": [
28+
"--profile=testing-debug",
2829
"--extensionDevelopmentPath=${workspaceFolder}",
2930
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index",
3031
"${workspaceFolder}/assets/test"
3132
],
3233
"outFiles": [
3334
"${workspaceFolder}/out/test/**/*.js"
3435
],
35-
"preLaunchTask": "compile"
36+
"preLaunchTask": "compile-tests"
3637
}
3738
]
3839
}

.vscode/tasks.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
}
1919
},
2020
{
21-
"label": "compile",
21+
"label": "compile-tests",
2222
"type": "npm",
23-
"script": "compile",
23+
"script": "compile-tests",
2424
"problemMatcher": "$tsc",
2525
"presentation": {
2626
"reveal": "never"

.vscode/testing-debug.code-profile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "testing-debug",
3+
"extensions": "[{\"identifier\":{\"id\":\"ms-vscode-remote.remote-containers\",\"uuid\":\"93ce222b-5f6f-49b7-9ab1-a0463c6238df\"},\"displayName\":\"Dev Containers\"},{\"identifier\":{\"id\":\"vadimcn.vscode-lldb\",\"uuid\":\"bee31e34-a44b-4a76-9ec2-e9fd1439a0f6\"},\"displayName\":\"CodeLLDB\"}]"
4+
}

CONTRIBUTING.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ Please keep your PRs to a minimal number of changes. If a PR is large, try to sp
3838

3939
### Testing
4040

41-
Where possible any new feature should have tests that go along with it, to ensure it works and will continue to work in the future. When a PR is submitted one of the prerequisites for it to be merged is that all tests pass. You can run tests locally using either of the following methods:
41+
Where possible any new feature should have tests that go along with it, to ensure it works and will continue to work in the future. When a PR is submitted one of the prerequisites for it to be merged is that all tests pass.
42+
43+
To get started running tests first import the `testing-debug.code-profile` VSCode profile used by the tests. Run the `> Profiles: Import Profile...` command then `Select File` and pick `./.vscode/testing-debug.code-profile`.
44+
45+
Now you can run tests locally using either of the following methods:
46+
4247
- From VSCode, by selecting "Extension Tests" in the Run and Debug activity.
4348
- Using `npm run test` from the command line (when VS Code is not running, or you'll get an error)
4449

assets/test/.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"args": [
77
"build",
88
"--build-tests",
9-
"--verbose"
9+
"--verbose"
1010
],
1111
"cwd": "defaultPackage",
1212
"problemMatcher": [
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// swift-tools-version:5.10
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "defaultPackage",
8+
platforms: [
9+
.macOS(.v13)
10+
],
11+
dependencies: [
12+
.package(url: "https://github.com/apple/swift-testing.git", branch: "main")
13+
],
14+
targets: [
15+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
16+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
17+
.executableTarget(
18+
name: "PackageExe",
19+
dependencies: ["PackageLib"]
20+
),
21+
.target(
22+
name: "PackageLib",
23+
dependencies: []
24+
),
25+
.testTarget(
26+
name: "PackageTests",
27+
dependencies: [
28+
"PackageLib",
29+
.product(name: "Testing", package: "swift-testing")
30+
]
31+
),
32+
]
33+
)
Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,42 @@
1-
import XCTest
21
import PackageLib
2+
import XCTest
3+
4+
final class PassingXCTestSuite: XCTestCase {
5+
func testPassing() throws {}
6+
}
7+
8+
final class FailingXCTestSuite: XCTestCase {
9+
func testFailing() throws {
10+
XCTFail("oh no")
11+
}
12+
}
13+
14+
final class MixedXCTestSuite: XCTestCase {
15+
func testPassing() throws {}
16+
17+
func testFailing() throws {
18+
XCTFail("oh no")
19+
}
20+
}
21+
22+
#if swift(>=5.10)
23+
import Testing
24+
25+
@Test func topLevelTestPassing() {}
26+
@Test func topLevelTestFailing() {
27+
#expect(1 == 2)
28+
}
29+
30+
@Suite
31+
struct MixedSwiftTestingSuite {
32+
@Test
33+
func testPassing() throws {}
34+
35+
@Test
36+
func testFailing() throws {
37+
#expect(1 == 2)
38+
}
339

4-
final class DefaultPackageTests: XCTestCase {
5-
func testExample() throws {
6-
// This is an example of a functional test case.
7-
// Use XCTAssert and related functions to verify your tests produce the correct
8-
// results.
9-
XCTAssertEqual(a, "B")
10-
}
40+
@Test(.disabled()) func testDisabled() {}
1141
}
42+
#endif

docker/docker-compose.2004.56.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
services:
42

53
runtime-setup:

docker/docker-compose.2004.57.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
services:
42

53
runtime-setup:

0 commit comments

Comments
 (0)