artofthesmart / QUnitGS2

A Google Apps Script library that brings the power and simplicity of QUnit unit testing to your scripts and applications. In just 60 seconds you can add unit testing to any script.
MIT License
23 stars 1 forks source link

Testing procedures calling helper functions or other procedures #11

Open tomfidos opened 3 years ago

tomfidos commented 3 years ago

Hi,

I try to test a quite long procedure onClick, see below, (I mean here a procedure as understood in JS: returning nothing, just writing calculation results out into a Google sheet) that consists of many other sub-procedures or functions.

Whereas testing a single function (a function as understood in JS: returning something; some of these functions don't take an input) or procedure (some of them take an input) all works fine and according to instructions from: http://qunitgs2.com/.

However tests for that long procedure (using successfully tested single functions/procedures) don't work: after depolying the test code as a web app and clicking latest code (everything exactly as by previously described code tests) a html tab pops out with a proper header, etc, but no tests run. What is more the test code doesn't call the tested procedure at all. However, it was calling tested single functions/procedures; they run and changed the sheet they worked on. Moreover, they don't need to be included in assert object.

Does it mean that it's impossible to test such procedures: being a set of other functions or procedures? Or is it something else?

Here the test suit:

let QUnit = QUnitGS2.QUnit;

function doGet() {
    QUnitGS2.init();

    QUnit.module('Script test');

    QUnit.test('onClick function', function(assert) {
        //when
        onClick();  // At the end it writes a figure in a sheet's G11 cell. 
        //then
        assert.equal(mainSheet.getRange('G11').getValue(), '2.10970231', 'provides correct total balance after running script');
    });

    QUnit.start();
    return QUnitGS2.getHtml();
}

function getResultsFromServer() {
    return QUnitGS2.getResultsFromServer();
}
andrewroberts commented 3 years ago

Where is mainSheet defined?

Also try deploying the web app, using the "latest code" can sometimes have unexpected effects.

tomfidos commented 3 years ago

Thanks for a quick reply.

That was a good remark about the mainSheet. Although it is defined in the tested code file, the test code didn't "see" it. I've added its definition to the tests and now at least they call onClick which does its job in the sheet.

Nevertheless, still no tests are shown as run and completed in the deployed web app (which I deploy instead of clicking latest code as advised).

tomfidos commented 3 years ago

Any new insights in this topic?