A step-by-step guide for automatically smoke testing a Go application every time it's deployed to Heroku.
In this tutorial I will describe how to build an automated continuous testing pipeline for a Go application using Heroku Review Apps, GitHub, and Assertible. The primary goal is to automatically execute smoke tests against our web service every time it's deployed.
Executing automated tests against staging and review application environments is a fantastic way to reduce the need for manual testing and prevent bugs from sneaking into production.
Heroku Review apps is a very convenient way to continuously test a web service because it seamlessly integrates with GitHub pull requests. After enabling the pipeline described in this post we can:
- Link directly to the deployed testing applications from GitHub pull requests
- View test results directly in pull requests status checks
- Prevent merging broken applications by smoke testing with Assertible
- Setup a Heroku app with Review Apps enabled
- Configure an Assertible web service
- Connect Assertible web service to GitHub
- Push code to a pull request
The testing technique described in this post is not specific to application written in Go. However, the code in the example repository uses Go and the language is increasingly being used to create web applications and APIs, making it a great choice for automated QA testing.
Example repo: https://github.com/assertible/go-heroku-example
1. Configure Heroku and enable Review Apps
Setting up Heroku with Review Apps can be done quickly. If you are already using Heroku Review Apps, skip to step 2.
Create a new app on Heroku
I won't be describing this part in detail because it's well-documented elsewhere. See the post Go + Heroku : Hello World for more details.
Create a new Heroku Pipeline for your application
In the Heroku dashboard, navigate to the Deploy tab for your application:
Click New Pipeline then Create Pipeline. After the pipeline is created, you should be redirected to an overview for the pipeline.
Next, connect the pipeline to GitHub
In the pipeline overview, there should be a Connect to GitHub button. Otherwise, navigate to Settings for the pipeline. You should see an input to connect the pipeline directly to a GitHub repository.
Insert your web service's GitHub repository name in the text area and click Search then Connect
Navigate back to the Pipeline overview, then click Enable Review Apps...
app.jsonfile is required to use review apps which describes buildpacks, addons, and other dependencies your application requires to be initialized correctly. For the purposes of this post, I clicked the Create an app.json File... button, which automatically created the example repo app.json file.
In the same dialogue, click the option labeled Create new review apps for new pull requests automatically
I've also enabled Destroy stale review apps automatically.
Neither of these options are strictly necessary. Assertible will automatically test manually created review apps too (they are just less convenient)
Finally, click Enable
The end result should be a new Heroku Pipeline ready to deploy review apps. If you create a new Pull Request on GitHub, you will see a new Review App in the left column labeled Review Apps (more on that in step 4):
2. Configure an Assertible web service
The next step is to configure your web service in Assertible. Luckily, this part is simple:
Sign up for an Assertible account
Navigate to the Assertible signup page. And create a new account by clicking the Sign up with GitHub button.
Create a web service in Assertible with the same same URL as your Heroku app
After you create a new account in Assertible, you will be prompted to create a web service.
Make sure the Initialize this web service with a test is option enabled. After your service is created, run your tests a few times to ensure everything is configured correctly.
3. Connect Assertible web service to GitHub
Now that you have a web service configured in Assertible, you need to connect it to GitHub to receive deployment events for the repository.
Navigate to the Deployments tab for your Assertible web service
Select GitHub integration in the left-hand column
Finally, select a repository
In the Select a repo drop-down, select or type in your repository name.
When Heroku deploys your application, Assertible receives deployment events for that repository and will automatically run your tests.
How it works: Every time you push commits to a pull request Heroku creates or updates the review app corresponding to that branch. GitHub will send webhooks to Assertible which automatically executes tests against the unique web service being deployed, even if it has a random unique URL. See the GitHub deployment integration docs for a more detailed explanation.
4. Push code to a pull request
Good news! The hard part is over. The only thing remaining task is to change some code, push a branch, and create a pull request for your repository.
When the pull request is created, you will see the Heroku deployment and subsequent test result status from Assertible.
Congratulations, you have built an automated continuous testing pipeline for your Go application.
Automatically testing production
At some point, you'll want to extend that pipeline to test other
Heroku can automatically deploy your code to production when a pull
request is merged or commits are pushed directly to
feature is called automatic deploys. When automatic deployments
are enabled, Assertible will automatically run checks against your
production application and report status checks to the exact sha1 in
your GitHub repository.
To enable this feature, navigate to your app's pipeline in the Heroku dashboard and open the options menu for the production application.
When the dialogue pops up, click Enable Automatic Deploys. If you are using a continuous integration service, I highly recommend enabling the Wait for CI to pass before deploy.
In Assertible, you need to configure a new environment which matches
the name of your Heroku application. For
the example app
I have created an environment named
That's it! Now every time your production service is deployed, Assertible will automatically run smoke tests to validate your web service's functionality. You can configure tests in Assertible to validate response bodies using JSON Schema or HTML validation, check data integrity using JSON path selectors, or run link checkers on an HTML page. See our assertions documentation for more details.
If you are deploying to production manually or as part of a continuous-delivery process that does not use Heroku, there are several other examples for how to propogate deployment events to GitHub from scripts and CI pipelines in our [documentation](/docs/guide/deployments) and [deployments example repository](https://github.com/assertible/deployments).
Examples and resources:
- Heroku Review Apps
- How to create a new Heroku app
- Heroku Review Apps
- GitHub repo assertible/go-heroku-example
- Automating QA pipelines for Heroku Review Apps
:: Christopher Reichert
The easiest way to test and
monitor your web services
Reduce bugs in web applications by using Assertible to create an automated QA pipeline that helps you catch failures & ship code faster.Get started with GitHubSign up for free
New feature: Encrypted variables 10/30/2019
New feature: Smarter notifications 5/17/2019