UI Tests: The Illusion of Quality at the Cost of Quality

UI-based tests are often the de facto method of verifying software correctness in many organizations. It involves deploying the software, making sure all the integration points are hooked up, and then having people attack the UI using tests cases that were developed (often in isolation) to ensure the software meets specification. Much has been written about the downside of this approach which ends up resulting in slow and brittle tests. It is the main reason why automation pyramids suggest that UI-based tests be the smallest number of tests written in a suite....

May 9, 2022

Using Gherkin for Acceptance Criteria

I’ve had a mixed experience working with Gherkin and Cucumber, and the culprit has usually been the step definitions. Consider the following scenario: GIVEN the client is logged in WHEN the client accesses their portfolio THEN the client sees their balance AND the client sees an option to transfer funds This requires four methods to be declared which implement each step. The implementation of these methods tends to result in UI-tests as that is often the natural way to look at software....

August 25, 2021

Avoiding Duplication in State Management

State management is where small bugs grow up to become evil villains, rendering applications a nightmare to maintain. This is especially true when writing JavaScript to maintain UI state. It is tempting to create instance variables which maintain state which are then queried in template logic. For example: my-component.ts class MyComponent { language: string constructor(private myStore: MyStore) {} changeLanguage(lang: string) { // set this.language based on myStore } } my-component.html...

May 4, 2021

Mocking and Spying with Jest and TypeScript

I have found that the easiest way to mock TypeScript objects using Jest is by simply doing this: const obj = { prop1: "some string prop", prop2: 50 } as any as MyType Now we can use obj anywhere MyType was expected and can use jest.spyOn(obj, ...) to the heart’s content. Frameworks like jest-mock-extended do similar work but I find that they’re an unnecessary abstraction that prevent the test from being expressive and obvious....

April 22, 2021