Node JS Tape Unit Testing : All cases inside one function for a method

by hatellla   Last Updated November 01, 2017 23:05 PM

I am using tape for unit testing in Node JS. I wanted to ask one thing about better coding while writing unit testing.

When using different inputs to a single method, is it a better idea to use all cases inside one test function or different cases of single method in different test function?

test('getXYZ: get XYZ from db',
    function testGetXYZ(t) {

        var expected = 'string';
        var actual = utils.getXYZ("dassa", "dasds");

        t.equal(actual, expected);

        var expected = 'string';
        var actual = utils.getXYZ("dassa", "dasds");

        t.equal(actual, expected);

        t.end();
});

or,

test('getXYZ1: get XYZ from db',
    function testGetXYZ1(t) {

        var expected = 'string';
        var actual = utils.getXYZ("dsa", "eqwew");

        t.equal(actual, expected);

        t.end();
    });

test('getXYZ2: get XYZ from db',
    function testGetXYZ2(t) {

        var expected = 'string';
        var actual = utils.getXYZ("dsa", "eqwew");

        t.equal(actual, expected);

        t.end();
});

While writing all cases inside one function, the only problem I faced is my JS Lint start throwing an error saying method body is too large.

So, please suggest which is the better way to write Unit tests in Tape?



Related Questions


What to do to during unit testing

Updated June 07, 2016 08:02 AM

Nodejs app structure for extensive testing

Updated May 13, 2015 12:40 PM

What is IBM's CUPRIMDS?

Updated February 18, 2017 10:05 AM

What does stubbing mean in programming?

Updated March 03, 2017 13:05 PM

Integration tests, but how much?

Updated February 28, 2017 08:05 AM