AutofixtureTS

AutoFixture for TypeScript


Project maintained by RonnieHegelund Hosted on GitHub Pages — Theme by mattgraham

Project Description

Write maintainable unit tests, faster.

AutoFixtureTS is inspired by AutoFixture. AutoFixtureTS makes it easier for TypeScript developers to do Test-Driven Development by automating non-relevant Test Fixture Setup, allowing the Test Developer to focus on the essentials of each test case.

Overview

(Jump straight to the CheatSheet if you just want to see some code samples right away.)

AutoFixtureTS is designed to make Test-Driven Development more productive and unit tests more refactoring-safe. It does so by removing the need for hand-coding anonymous variables as part of a test's Fixture Setup phase.

When writing unit tests, you typically need to create some objects that represent the initial state of the test. Often, an API will force you to specify much more data than you really care about, so you frequently end up creating objects that has no influence on the test, simply to make the code compile.

AutoFixtureTS can help by creating such Anonymous Variables for you. Here's a simple example:

it("IntroductoryTest", () =>{        
        // Fixture setup
        var sut = new AutofixtureTS.Fixture();        
        // Exercise system                
        var expectedNumber = sut.CreateAnonymous(0);
        // Verify outcome
        expect(expectedNumber).toBe(1)
        // Teardown
    });

This example illustrates the basic principle of AutoFixtureTS: It can create values of virtually any type without the need for you to explicitly define which values should be used.