{"id":13448699,"url":"https://github.com/maelcaldas/gs-test-runner","last_synced_at":"2025-03-22T17:32:18.988Z","repository":{"id":30706099,"uuid":"34262165","full_name":"maelcaldas/gs-test-runner","owner":"maelcaldas","description":"Google Apps Script library for testing and CI","archived":false,"fork":false,"pushed_at":"2020-01-14T13:31:28.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-31T06:11:26.723Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maelcaldas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-20T13:29:07.000Z","updated_at":"2024-07-31T06:11:26.723Z","dependencies_parsed_at":"2022-08-26T09:00:26.215Z","dependency_job_id":null,"html_url":"https://github.com/maelcaldas/gs-test-runner","commit_stats":null,"previous_names":["bkper/gstestrunner"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maelcaldas%2Fgs-test-runner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maelcaldas%2Fgs-test-runner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maelcaldas%2Fgs-test-runner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maelcaldas%2Fgs-test-runner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maelcaldas","download_url":"https://codeload.github.com/maelcaldas/gs-test-runner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221832218,"owners_count":16888196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T06:00:17.848Z","updated_at":"2024-10-28T13:30:45.976Z","avatar_url":"https://github.com/maelcaldas.png","language":"JavaScript","funding_links":[],"categories":["Testing"],"sub_categories":[],"readme":"[TDD]: http://en.wikipedia.org/wiki/Test-driven_development\n[GSUnit]: https://sites.google.com/site/scriptsexamples/custom-methods/gsunit\n[CI]: http://en.wikipedia.org/wiki/Continuous_integration\n[Google Apps Script]: https://developers.google.com/apps-script/\n[Development Mode]: https://developers.google.com/apps-script/guide_libraries#testAndDebug\n[GSTestRunner]: http://developers.bkper.com/docs/GSTestRunner\n[GSTestRunner.runSuite]: http://developers.bkper.com/docs/GSTestRunner/global.html#runSuite\n[GSTestRunner.runTest]: http://developers.bkper.com/docs/GSTestRunner/global.html#runTest\n[GSTestRunner.getSuiteResult]: http://developers.bkper.com/docs/GSTestRunner/global.html#getSuiteResult\n\n\n# GSTestRunner  [![GSTests status](https://gs-tests-status.appspot.com/badge.svg?suite=GSTestRunner\u0026namespace=bkper)](https://script.google.com/macros/s/AKfycbyWJJFIwoqnNudRMGse18qVNWw5aa7g03-iLmL_rjqO8mg-MjI/exec?suite=GSTestRunner\u0026namespace=bkper)\n\n[Google Apps Script] library to **run tests**, **publish results** and send **email notifications** of test failures.\n\n[GSTestRunner] helps with [TDD] and also let you set a lightweight [CI] for your Apps Script codebase.\n\nIt does NOT provide assertions. For that, we suggest [GSUnit].\n\n#Get started\n\nAdd the library through project key: **Mv3gVv8-YsY7WWlQhoAGWgpNuZToV6OsP**\n\nCreate a script with test methods starting with `test`:\n\n````javascript\n\nfunction runSuite() {\n  GSTestRunner.runSuite(this, \"Get Started\");\n}\n\nfunction testA_() {\n  Logger.log(\"Good code!\");\n}\n\nfunction testB_() {\n  Logger.log(\"Bad code!\");\n  nonExistingFunction();\n}\n\n\n````\n\nThen, run the suite passing `this` as the suite object, and set a trigger to periodically run the test suite, depending on your needs - every hour would be good ;)\n\nThe results based on code above can be found by clicking here: [![GSTests status](https://gs-tests-status.appspot.com/badge.svg?suite=Get%20Started\u0026namespace=bkper)](https://script.google.com/macros/s/AKfycbyWJJFIwoqnNudRMGse18qVNWw5aa7g03-iLmL_rjqO8mg-MjI/exec?suite=Get%20Started\u0026namespace=bkper)\n\nIf you are testing another library, don't forget to let the [Development Mode] on, so the test will run always on latest code version.\n\n#Suite names\n\nTo avoid conflicts, **the suiteName must be unique**. If someone already taken the name, you will get an error like this:\n\n `Suite name \"Get Started\" already taken! Change the name and/or namespace, or ask one of those guys to include you as recipient: [xxx@gmail.com]`\n\nYou can do either:\n - Change the name and/or namespace, on [options](#options)\n - Ask the ones who already taken that suite name to include you, by adding your email to the [options](#options)**.recipient** and running the suite at least once.\n\n\n#Befores and Afters\n\nSometimes you need to setup and cleanup fixtures before and after tests. If implemented, [GSTestRunner] run the following functions, in respective order:\n\nFunction      | Order\n------------- | -------------\nbeforeSuite_  | Before all tests\nbeforeTest_   | Before each test\nafterTest_    | After each test\nafterSuite_   | After all tests\n\nExample:\n\n````javascript\n\n//Befores and Afters\nfunction beforeSuite_() {\n  Logger.log(\"Run before all tests\");\n}\nfunction beforeTest_() {\n  Logger.log(\"Run before each test\");\n}\n\nfunction afterTest_() {\n  Logger.log(\"Run after each test\");\n}\nfunction afterSuite_() {\n  Logger.log(\"Run after all tests\");\n}\n\n````\n\n\u003ca name=\"options\"\u003e\u003c/a\u003e\n#Options\n\nWhen calling [GSTestRunner.runSuite] you can pass some options as the third parameter, that can change the behavior:\n\n\n  Option    |  Type   | What it does\n----------- | ------- | ------------\nnamespace   | string  | Define a namespace to avoid suite naming colisions\nnotify      | boolean | Send email notifications to recipient when test fails\nrecipient   | string  | Comma separated emails to receive failure notifications\nerrorOnFail | boolean | Throw error when suite fails. Good for development.\ntestCodeUrl | string  | The URL of test script code, to be linked on results\n\nExample:\n\n````javascript\n\nfunction runSuite(event) {\n\n  //Trick to know if is triggered by time trigger\n  var isRunningByTimeTrigger = event != null;\n\n  var options = {\n    namespace: \"bkper\",\n    notify: isRunningByTimeTrigger,\n    recipient: \"bkper-dev@googlegroups.com\",\n    errorOnFail: !isRunningByTimeTrigger,\n    testCodeUrl: \"https://script.google.com/a/nimbustecnologia.com.br/d/19IiyKv3t5WlqDLcDWwMO8Y_eBeWaNJyP9kZiPSGECT8GCrbFlBw_28B-/edit\",\n  }\n\n  GSTestRunner.runSuite(this, \"Get Started\");\n}\n\n````\nTake a look at the trick to know if the suite is running by a time trigger, or manually. Its good to avoid unnecessary email notifications when running manually.\n\n#Suite result\n\nYou can see the results of a test suite by checking the log after calling [GSTestRunner.runSuite].\n\nEverytime you run a test suite, the results are stored for later retrieval by calling [GSTestRunner.getSuiteResult]:\n\n````javascript\n\nfunction logSuiteResult() {\n  var result = GSTestRunner.getSuiteResult(\"Get Started\", \"bkper\");\n  Logger.log(\"status: \" + result.status);\n  Logger.log(\"url: \" + result.url);\n}\n\n````\nResults are also published to a simple web view, and can be accessed through the url logged above.\n\n#Running a single test\n\nYou can run a single test by calling [GSTestRunner.runTest]:\n\n````javascript\n\nfunction runASingleTest() {\n  GSTestRunner.runTest(this, \"testA_\");\n}\n\nfunction testA_() {\n  Logger.log(\"Good code!\");\n}\n\n````\nWhen you run a single test, the results are NOT stored neither published to web view.\n\n#Status badges\n\nWith [GSTestRunner], you can embed little status badges into your project's README or general documentation. That way, visitors of your projects or site can immediately see its test status.\n\nTo get the links, on suite result page, just click on badge:\n\n![Status Badge links](https://gs-tests-status.appspot.com/badge.svg?suite=BkperApp\u0026namespace=bkpertest)\n\n\n#Complete example\n\nThe complete code for this guide can be found [here](https://script.google.com/a/nimbustecnologia.com.br/d/19IiyKv3t5WlqDLcDWwMO8Y_eBeWaNJyP9kZiPSGECT8GCrbFlBw_28B-/edit)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaelcaldas%2Fgs-test-runner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaelcaldas%2Fgs-test-runner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaelcaldas%2Fgs-test-runner/lists"}