TestGAS helps you write better Google Apps Script
The TestGAS
library makes it easy to write small tests on Google Apps Script
, yet scales to support complex functional testing for applications and libraries.
Usage
Import
You can import this library by this script ID.
1CRjWWWYfjD7WzPl43RB1BiD7XDLJmR03eEpXr2LMh75yAq5qMlczOIfm
If you cannot use...
Maybe, your files are older than this library.
So, you should remake .gs
script files to use this library.
Getting started
An example of a simple test:
Result of executing execute_Test_sample
:
[ 'test_sample_1', 'test_sample_2' ] TestGAS starts: "Test_sample" ...... TestGAS terminated: "Test_sample". ====================================================== FAILURES ====================================================== ______________________________________________ test_sample_1 ______________________________________________ AssertionError: Actual value is not equal to Expected value. actual : 3 expected: 4 =================== 1 failed, 1 passed of all 2 tests in 0.01 seconds ===================
Features
Methods
Reference
createExecutor ()
Creates Executor
object.
Executor
runs test and display result of test.
Arguments
name | type | description |
---|---|---|
(nothing) | (nothing) | (nothing) |
Example
Executor.executeTestGas (executingTestClass, arraySkippingTest=[])
Runs test and display result of test.
Arguments
name | type | description |
---|---|---|
executingTestClass | Object | Executor of TestGAS. |
arraySkippingTest | string[] | array of functions that test is being skipped. |
Example
tester.executeTestGas(Test_TestGas)
returns array of functions that test failed from Test_TestGas
object.
Furthermore, you can specify testcases that you don't wanna test.
In the code above, test_plus_1_3
is skipped in the test.
Executor.assertEquals (actual, expected, willOutputErrorToReport=true)
Asserts that actual value and expected value are same or not.
Arguments
name | type | description |
---|---|---|
actual | any | Actual value. |
expected | any | Expected value. |
willOutputErrorToReport | boolean | Set true if you wanna display result of a testcase. Set false otherwise. |
test_arrayLength_1_1
's test is passing. test_arrayLength_1_2
's test is failing.
Executor.assertEqualsArrayLength (actual, expected, willOutputErrorToReport=true)
Asserts that actual array and expected array are same or not in the point of view of length.
Arguments
name | type | description |
---|---|---|
actual | any | Actual array. |
expected | any | Expected array. |
willOutputErrorToReport | boolean | Set true if you wanna display result of a testcase. Set false otherwise. |
Example
test_arrayLength_1_1
's test is passing. test_arrayLength_1_2
's test is failing.
Executor.assertEqualsArrayItems (actual, expected, willOutputErrorToReport=true)
Asserts that actual array and expected array are same or not.
Arguments
name | type | description |
---|---|---|
actual | any | Actual array. |
expected | any | Expected array. |
willOutputErrorToReport | boolean | Set true if you wanna display result of a testcase. Set false otherwise. |
Example
test_arrayLength_1_1
's test is passing.
Tests of test_arrayLength_1_2
and test_arrayLength_1_3
are failing.
Executor.assertNotEquals (actual, expected)
Asserts that actual value and expected value are NOT same or same.
Arguments
name | type | description |
---|---|---|
actual | any | Actual value. |
expected | any | Expected value. |
Example
test_arrayLength_1_1
's test is passing. test_arrayLength_1_2
's test is failing.
Executor.assertError (func, funcArgs, expectedErrorName, willOutputErrorToReport=true)
Asserts that a function call raises expected_exception or raise a failure exception otherwise.
Arguments
name | type | description |
---|---|---|
func | Function | A function targeted for test. |
funcArgs | any[] | Arguments of function. |
expectedErrorName | Error | Error name you expect. |
willOutputErrorToReport | boolean | Set true if you wanna display result of a testcase. Set false otherwise. |
Example
If that function arrayLengthIsOneToItem(arrays)
throws RangeError
, that assertion is passing.
Executor.assertNotError (func, funcArgs, expectedErrorName, willOutputErrorToReport=true)
Asserts that a function call NOT raises expected_exception or raise a failure exception otherwise.
Arguments
name | type | description |
---|---|---|
func | Function | A function targeted for test. |
funcArgs | any[] | Arguments of function. |
expectedErrorName | Error | Error name you don't expect that it may thrown. |
willOutputErrorToReport | boolean | Set true if you wanna display result of a testcase. Set false otherwise. |
Example
If that function arrayLengthIsOneToItem(arrays)
doesn't throw RangeError
, that assertion is passing.