-
Notifications
You must be signed in to change notification settings - Fork 9
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
[Meta] Test conventions brain dump #125
Comments
Angular apps should enable errorOnUnknownElements and errorOnUnknownProperties in their TestBeds: https://dev.azure.com/ni/DevCentral/_workitems/edit/2446157/ jasmine test suites should elevate |
Nimble has a handy pattern for parameterized tests that allows individual cases to be focused / disabled, etc. Handy for dealing with intermittency or debugging a specific case: ni/nimble#1379 Maybe it should be published as a package or a documented convention or maybe an existing package exists that would be better to standardize on, never looked. Such a tool could maybe be a package from the styleguide, Edit: Nimble's parameterize pattern has been published as |
Helper functions should not close around existing state (instead have values as parameters) and should not contain expect statements. Instead helpers should calculate some value that can be used in an expect statement. Keep test logic and expect statements separated. Example discussion: ni/nimble#1335 (comment) Notes:
|
Avoid conditionally executing expect statements which is a pattern that emerges from new updates / modifications to parameterized tests pretty often. Some alternatives are:
Refinement: Another example of conditionally executing expects is looping over expect statements from none statically defined test state Example: for (const val of obj.dynamicValues()) {
expect(val).toBe(true);
} In this example if Alternative: Have the tests have a statically defined set of values to compare to: const expected = [true, true, true];
const actual = obj.dynamicValues();
expect(actual).toEqual(jasmine.arrayWithExactContents(expected)); Alternative (discouraged): This alternative should be discouraged. Without statically defined expectations it takes much more debugging or actual runtime evaluation to interpret test code. As a last result / bare minimum create an expect of the number of expect cases that should run. // Unfavored alternative
const actual = obj.dynamicValues();
expect(actual.length).toBe(3);
for (const val of actual) {
expect(val).toBe(true);
} Refinement 2: Looped expects also make it harder to debug tests. Line number no longer points to an expect with a clear responsibility. More discussion here: ni/nimble#1620 (comment) |
Prefer to use jasmine spy / spies to track events / callbacks instead of tracking and mutating a state
Example spy usage but make sure to use an appropriate assertion based on what you need to check, i.e. |
Be aware of and use the jasmine asymmetric equality testers when appropriate over custom processing code such as |
A collection of thoughts on Jasmine page objects for components
We probably also want conventions for Playwright page objects and Playwright tests in general. |
It would be nice to capture clearer guidance about how to write Angular component "unit" tests. Should we try to make them pure unit tests with all dependencies mocked? Should services be providing mocks of themselves for other components' tests to use? Should most tests actually be integration tests with real dependencies? There's a bit more discussion in NI internal SO https://ni.stackenterprise.co/questions/1051/1123#1123 |
Frankly, I question whether we would ever produce a document on this topic short enough someone would use it. This is not a question unique to NI, and it's still has not been defined in a workflow diagram. It's an art, not a science - or really, the people who do it best answer each of these questions on a case by case basis. Maybe this is best solved with ChatGPT? Give it your situation, and allow it to produce a tailored answer.
When the questions a document attempts to answer are so situationally dependent, it becomes questionable whether it should be written. Change my mind. |
Describe the issue
Making an issue to just start gathering things that if maybe someone was making test conventions would be useful to include / consider.
This issue is just a raw brain dump / discussion thread. Feel free to add items as comments
The text was updated successfully, but these errors were encountered: