This repository was archived by the owner on Jun 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Iss2213 - docs for the test result provider #868
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
057340c
Ignore broken algolia links
jt-nti d0270e0
Ignore broken algolia links (#863)
jt-nti c3bc0f3
Add IMS TM Managers link to top level Managers page
ideeley ccd9b85
Add IMS TM Managers link to top level Managers page (#861)
jt-nti 9bbf892
Fix incorrect annotation in documentation - it should be ContinueOnTe…
jadecarino b83002d
Add documentation for the TestResultProvider annotation
jadecarino b459a73
Merge branch 'main' of github.com:galasa-dev/galasa.dev into iss2213-…
jadecarino d04eefd
Merge branch 'next' of github.com:galasa-dev/galasa.dev into iss2213-…
jadecarino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/markdown-pages/docs/writing-own-tests/test-result-provider.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| --- | ||
| path: "/docs/writing-own-tests/test-result-provider" | ||
| title: "Controlling code execution after test failure" | ||
| --- | ||
|
|
||
| As a tester, you may want the ability to access the result so far of a Galasa test at different points during the test lifecycle, to control the execution of code based on that result. | ||
|
|
||
| The `ITestResultProvider` can be used to get the test result so far after the first method invokation in a test. It can give you access to if the test is in Passed or Failed state. You can then check the result so far in your test code and choose to call or not call non-test methods based on this. | ||
|
|
||
| The annotation `@TestResultProvider` injects a `ITestResultProvider` object into your test class. The Core Manager updates the provider with the test result so far after each `@BeforeClass`, `@Before`, `@Test`, `@After` and `@AfterClass` method. | ||
|
|
||
| To use this capability, simply include the lines of code below in your test: | ||
|
|
||
| ```java | ||
| @TestResultProvider | ||
| public ITestResultProvider testResultProvider; | ||
| ``` | ||
|
|
||
| In the example below, the `@AfterClass` method retrieves the result from the `ITestResultProvider` and checks if it is Failed. If the result is Failed, the method `myCustomCleanupMethod` is called which could contain some diagnostic collection or clean up of resources, which the tester only wants to be run if the test Failed. | ||
|
|
||
| ```java | ||
| @AfterClass | ||
| public void afterClassMethod() throws FrameworkException { | ||
| if (testResultProvider.getResult().isFailed()) { | ||
| myCustomCleanupMethod(); | ||
| } | ||
| } | ||
|
|
||
| private void myCustomCleanupMethod() { | ||
| try { | ||
| // Some custom cleanup logic that only happens on failures. | ||
| } catch(Exception ex) { | ||
| logger.error("Failing while cleaning up in myCustomCleanupMethod()"); | ||
| // Ignore the problem. | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| There can only be a single instance of the test result provider in each test. This is shared between any Galasa test class variables which are marked with the `@TestResultProvider` annotation. It makes no sense having multiple implementations as they all provide the same result when asked. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.