-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Reinstate and skip Dashboard and Visualize tests #15687
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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,32 @@ | ||
# Testing style guide | ||
|
||
## Principles | ||
|
||
* A good test helps you identify what broke and how so you can fix it quickly. A bad test tells you something is broken but wastes your time trying to figure out what and how. | ||
* Tests add time to the development cycle so we should write as few tests as possible, but no fewer. | ||
* **Unit tests** should cover 70% of our needs. They'll ensure our fundamentals are sound. | ||
* **Integrations tests** should cover 20% of our needs. They'll ensure our units work well together. | ||
* **End-to-end tests** should cover 10% of our needs. They'll ensure our primary user flows are intact and alleviate the burden of manual testing from our QA engineers. | ||
|
||
## Anti-patterns | ||
|
||
### Too many assertions in a single test | ||
|
||
A test's usability goes down as the number of assertions it contains goes up. The more assertions you make, the less clear the purpose of the test. | ||
|
||
Instead of doing this, try one of these alternatives: | ||
|
||
1. Try breaking up the test into multiple tests with individual assertions. This clarifies what you're testing. | ||
2. Try using Jest snapshots in lieu of multiple assertions about the state of the UI. This makes your test more concise and maps it more clearly to the appearance of the UI. | ||
|
||
### Testing concrete details instead of abstractions | ||
|
||
Let's say a feature in your UI consists of a form and a submit button. If you want to test that this feature is available, then making an assertion against the form inputs and submit button would be a test of the feature's concrete details. This would be a brittle test that's prone to being broken by changes to the form's design or to the UX of the feature. | ||
|
||
A better test would test for the abstract availability of this feature. For example, a `data-test-subj` selector on the container or some other proxy element to ensure the user has access to the feature. | ||
|
||
### PageObject method does too much | ||
|
||
### PageObject method contains conditional logic | ||
|
||
### PageObject is bloated |
This file contains 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
Empty file.
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel a bit like these numbers are arbitrary and don't accurately reflect our needs given the state of our code base. End to end tests require updating when our UI/UX changes, but they don't require updating when the inner code changes. Unit tests and integration tests require updating when our code changes, but not when the UI/UX changes. If we had a more stable code base then I think I'd agree that unit tests should be the focus, but we don't. Many of the bugs we actually find in production can't be covered by a unit tests. Unit tests aren't easy to create if the code doesn't have clear boundaries between logic and UI, which many places of our code base don't. In addition, a large portion of our codebase is in a transition from angular to react and undergoing a lot of clean up and refactoring. We should be writing unit tests for new code where possible, but I think code thats undergoing a big refactor means it's even more important to have end to end tests to ensure all the corner cases still work. It also eases the burden on our QA team.
I think a good principle to have is that any time a bug is encountered, write a test that would have caught it, whether it be a unit tests or an integration test, or an end to end test, but don't change the code prior to adding the test. I've been trying to do this and most of the time the only way to cover the test is an end to end test.