HomeToolsAbout

TDD Basics

Test Structure

Test should follow three steps:

Setup
Method
Validation/Assertion

Avoid Implementation of External Dependencies in Tests

You want to avoid external dependencies in test as much as possible.

Using things like dependency injection (and shallow-mocking the dependencies), you can avoid relying on the actual implementations to run properly for the test to pass.

// external dependencies and its implementation tested import ( someExternalFunction ) func testTightCoupling(someParam: string) boolean { testValue := someParam // calling actual implementation someExternalFunction(testValue); // assertion } // shallow dependencies using mock return value const mockedServiceMethod = mock(someExternalFunction) func testLooseCoupling() boolean { testValue := someParam }
AboutContact