A Word About Code Coverage in Testing

An important aspect of testing is to achieve good code coverage. This means, that you want to write tests for the majority of your code (both code files and line of code). There are tools that help you measure your code coverage - Testing library, Vitest comes with a built-in functionality: https://vitest.dev/guide/features.html#coverage It is worth noting though, that the goal is not necessarily 100% coverage. There always can be some code that doesn’t need any tests (e....

December 28, 2022 · 1 min · Daman Arora

Always Follow AAA Pattern When Writing Tests

Following is a very simple unit test which verifies if the add() function works correctly. While the test works, but it does not follow the AAA(Arrange, Act, Assert) pattern. import {it, expect} from 'vitest'; import { add } from './math'; it('should summarize all number values in an array', ()=>{ const result = add([1,2,3]) expect(result).toBe(6) }); Question: What is AAA (Arrange, Act, Assert) pattern in testing? AAA pattern allows you to write unit tests which are more readable and maintainable in long term....

December 27, 2022 · 1 min · Daman Arora