lundi 1 février 2021

How to remove repetetive unit tests?

Let's say I have the following class:

class Foo {
    public a( a, b ) {
        return this._exectute( {a,b} );
    }
    
    public b( a ) {
        return this._exectute( a );
    }

    private _execute( a ) {
        if ( ...condition... ) {
            throw new Error("Validation failed!"); 
        }

        return a;
    }
}

And I'd like to prepare a set of unit tests for it. Should I add a test that should check the condition both for a() and b()? Maybe only one method should check it? If so, which one? Or maybe I should use some other approach?

My goal is to reduce the number of unit tests and in this case, I've got the same test for both methods.

Aucun commentaire:

Enregistrer un commentaire