I'm trying to get set up with unit tests for google app scripts, and I found two projects:
https://code.google.com/p/gas-unit/ https://code.google.com/p/gasunit/
So I'm confused which to use :-)
I just had a go with the unhyphenated gasunit, which seems to expect that the script is embedded in a spreadsheet, which I am a little unclear on how to do ... and the scripts I want to test are web based scripts rather than spreadsheet ones
I had more luck testing the hyphenated gas-unit, which managed to send me both an email output of the test and generate a results page in my google site:
https://sites.google.com/site/testappscript2/TestResults
so I'm going to with gas-unit for the moment, but I'd really like to see some official testing framework incorporated by Google. In particular I'd like to find some way to get these scripts to be run with some frequency to send me the results. Also I'd love to get some BDD going; see my other posts:
How to get Cucumber/Capybara/Mechanize to work against external non-rails site how to use capybara has_text
Come on Google, you famously have "Testing Rocks, Debugging Sucks" in all your bathrooms? How about better testing support for Google Apps Scripts?
Run a test deploymentOpen the script project containing your add-on in the script editor. Click Run > Test as add-on. Under Execute Saved Test, find the test to execute and select it. Click Test.
Strict equality (===): a === b results in true if the value a is equal to value b and their types are also the same.
Unit testing is one of the steps in the software development process where every part or unit of code is verified to ensure it behaves as expected. When the code is modified in the future, the automated unit tests help ensure the existing functionality is intact. Unit tests can be done manually or coded.
You can try out QUnit for Google Apps Script. It is a patch for QUnit turned into a Google Apps Script library with API docs.
All you need is a script project that imports a QUnit library (for example the one with the project key MxL38OxqIK-B73jyDTvCe-OBao7QLBR4j
) and has a doGet function that configures QUnit using URL parameters and optionally also with your own settings, loads a function that runs your tests, and finally returns QUnit.getHtml(). Here is an example:
function doGet( e ) { QUnit.urlParams( e.parameter ); QUnit.config({ title: "Unit tests for my project" }); QUnit.load( myTests ); return QUnit.getHtml(); }; // Imports the following functions: // ok, equal, notEqual, deepEqual, notDeepEqual, strictEqual, // notStrictEqual, throws, module, test, asyncTest, expect QUnit.helpers(this); function myTests() { module("dummy module"); test("dummy test", 1, function() { ok(true); }); }
Then authorize the script, save a version of it, publish the script project ("Deploy as web app") and go to the test URL ("latest code") with your browser. Your tests will be run and results will be displayed via HtmlService. You can single-click on them to see their assertions, but as of writing this, you will probably not be able to do so in Firefox 20 and 21 due to Caja issue 1688.
I just wrote another testing framework named GasT for my google spreadsheet add-on development & testing.
GasT is a TAP-compliant testing framework for Google Apps Script. It provides a simple way to verify that the GAS programs you write behave as expected. https://github.com/huan/gast
My goal is to get a simple tap tool like tape(for javascript) or bats(for bash). the test suite format is quite clear:
var gastLibUrl = 'https://raw.githubusercontent.com/zixia/gast/master/src/gas-tap-lib.js' eval(UrlFetchApp.fetch(gastLibUrl).getContentText()) var test = GasTap.setPrintDriver('Logger') function gast() { test('do calculation right', function (t) { var i = 3 + 4 t.equal(i, 7, 'I can calc 3 + 4 = 7') }) test('Spreadsheet exist', function (t) { var ss = SpreadsheetApp.openById('1TBJpvlW3WWney4rk1yW5N9bAP8dOMkWxI97dOtco-fc') t.ok(ss, 'I can open spreadsheet') }) test.finish() }
Hope someone will like it. :)
there's a online version, you can go to have a look on it here: https://docs.google.com/spreadsheets/d/19M2DY3hunU6tDQFX5buJmZ_f3E8VFmlqAtodyC-J8Ag/edit#gid=0&vpid=A1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With