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
Add documentation for custom test framework reporting (#3640)
* Add documentation for custom test framework reporting
* Apply suggestions from code review
Co-authored-by: Alex Rocha <[email protected]>
---------
Co-authored-by: Alex Rocha <[email protected]>
Copy file name to clipboardExpand all lines: jekyll/test_framework_addons.markdown
+68-1Lines changed: 68 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ There are 3 main parts for contributing support for a new framework:
17
17
18
18
-[Test discovery](#test-discovery): identifying tests within the codebase and their structure
19
19
-[Command resolution](#command-resolution): determining how to execute a specific test or group of tests
20
-
- Custom reporting: displaying test execution results in the test explorer
20
+
-[Custom reporting](#custom-reporting): displaying test execution results in the test explorer
21
21
22
22
## Test discovery
23
23
@@ -331,3 +331,70 @@ end
331
331
```
332
332
333
333
You can refer to implementation examples for [Minitest and Test Unit](https://github.com/Shopify/ruby-lsp/blob/d86f4d4c567a2a3f8ae6f69caa10e21c4066e23e/lib/ruby_lsp/listeners/test_style.rb#L10) or [Rails](https://github.com/Shopify/ruby-lsp-rails/blob/cb9556d454c8bb20a1a73a99c8deb8788a520007/lib/ruby_lsp/ruby_lsp_rails/rails_test_style.rb#L11).
334
+
335
+
## Custom reporting
336
+
337
+
To report test execution results to the extension side, frameworks should be hooked up with a custom reporter that sends
338
+
JSON RPC events. To hook up the custom reporter, add-ons should include all CLI arguments necessary as part of
# Normal shutdown flow, when all tests ran without crashing the test process itself
380
+
defafter_all_tests_finished_running
381
+
LspReporter.instance.shutdown
382
+
end
383
+
end
384
+
385
+
# This is required to cleanup the explorer in case the normal execution of tests errors. For example, if the user
386
+
# writes a bad require and the test process crashes before even starting to run examples
387
+
MyFrameworkGem.after_run_is_completed do
388
+
RubyLsp::LspReporter.instance.at_exit
389
+
end
390
+
```
391
+
392
+
{: .important }
393
+
The IDs and URIs used to report results **must match** the ones used during test discovery to ensure that the outcomes
394
+
are associated with the right items.
395
+
396
+
{: .note }
397
+
If your test framework is based on Minitest or Test Unit and leverages their reporting structure, you may not need to
398
+
add custom reporters. Instead, you can simply rely on the ones automatically registered and provided by the Ruby LSP.
399
+
400
+
See our reporters for [Minitest](https://github.com/Shopify/ruby-lsp/blob/main/lib/ruby_lsp/test_reporters/minitest_reporter.rb) and [Test Unit](https://github.com/Shopify/ruby-lsp/blob/main/lib/ruby_lsp/test_reporters/test_unit_reporter.rb) as examples.
0 commit comments