vendredi 1 juillet 2016

Verify unit tests are actually being ran, not just skipped over because it's poorly written

We're using sinon and mocha to do our unit tests. I've come up with the problem several times where I write some tests (Maybe in a promise, or a callback, or a stub) and the tests in these do not ever get hit, thus they aren't actually testing anything.

I can't imagine being the only one who has done this, so was wondering what people do to verify the test they wrote is actually being ran.

As an example:

// sStuff...

let myStub = sinon.stub(className, "classMethod", (result) => {
    // THIS will never be ran.
    expect(result).to.be.equal(5);
});

expect(myStub.callCount).to.be.equal(0);

// Stuff...

The test won't complain it wasn't ran, because we have the callCount check, but in reality, we're never calling something on className to have the classMethod function to be called and testing the result against 5.

Any common solutions? I couldn't think of search terms for this.

Thanks!

Aucun commentaire:

Enregistrer un commentaire