Introduction to Testing in Go (Golang)
Learn how to write effective unit and integration tests in Go, for web applications and REST APIs
Lo que serás capaz de hacer
Writing unit tests and integration tests is one of the most-neglected aspects of software development. All too often, a developer will find him or herself say "but it works on my computer!" when a project is presumed finished, only to discover that once taken out of the development environment, things don't work as expected. Well written unit tests and integration tests help to solve this problem, and in fact almost without exception will reduce overall development time, rather than adding to it. In addition, well-tested code almost always requires less maintenance, and the end product will have less down time. This course is focused on writing unit and integration tests in Go, a modern, type safe, compiled, and extremely fast programming language. It it is ideally suited for building safe, scalable, incredibly fast web applications, and it has powerful testing tools built right in. In this course, we will build four simple applications, and thoroughly test them: A command line application (CLI) that tries to determine if a user-entered number is prime or not; A simple web application that allows a user to log in and upload a profile picture; A simple REST API built on the same code base as the web application which allows users to authenticate using JWT tokens and perform operations against a Postgres database. We'll go through the entire authentication process, including using refresh tokens, and thoroughly test all aspects of the code. A simple Single Page Web Application (SPA), written in Vanilla JavaScript, that demonstrates how to use JWT and Refresh Tokens with a SPA, and how to test that functionality. For each of these projects, we will learn how to write unit tests for all functionality. We will learn how to test (among other things): Application routes Application handlers How to test multiple scenarios by writing and using table tests Database operations (using the Repository pattern) Application middleware User authentication (with sessions) User authentication (with JWT tokens) JWT token generation and validation Refresh token generation and validation Testing user input Writing to the terminal Adding cookies to a request Reading cookies from a response By the end of this course, you will have a solid understanding of how to write effective tests, and how to write testable code. Please note that this course requires you to download Docker Desktop from Docker. If you are a Udemy Business user, please check with your employer before downloading software.
- Learn how to write unit tests in Go
- Learn how to write integration tests in Go, and simplify them using Docker
- Learn how to create test suites in Go
- Learn how to create a simple web application and test handlers, middleware, database, and more
- Learn how to create a simple REST API in Go and test its endpoints
- Learn to to authenticate using JWT Tokens (and refresh tokens) and completely test all functionality
Temario
UNIDAD 1 - Introduction · 4 leccionesUNIDAD 1 - Introduction
UNIDAD 1 - Introduction
- Introduction
- About me
- Asking for help
- Mistakes: we all make them.
UNIDAD 2 - Setting up our Development Environment · 4 leccionesUNIDAD 2 - Setting up our Development Environment
UNIDAD 2 - Setting up our Development Environment
- What we'll cover in this section
- Installing Go
- Installing an IDE
- Installing Docker
UNIDAD 3 - Simple Testing · 11 leccionesUNIDAD 3 - Simple Testing
UNIDAD 3 - Simple Testing
- What we'll cover in this section
- Creating a simple command line application
- Writing a our first test for the isPrime() function
- Improving our test with table tests
- Checking test coverage
- Completing our table tests
- Improving our program to allow for user entered information
- Writing a test for the prompt() function
- Writing a test for the intro() function
- Testing user input - writing a test for the checkNumbers() function
- Updating readUserInput to make it testable, and then testing it
UNIDAD 4 - An Aside: Running individual tests & Test Suites · 3 leccionesUNIDAD 4 - An Aside: Running individual tests & Test Suites
UNIDAD 4 - An Aside: Running individual tests & Test Suites
- What we'll cover in this section
- Running a single test
- Running groups of tests (test suites)
UNIDAD 5 - Testing Web Applications · 11 leccionesUNIDAD 5 - Testing Web Applications
UNIDAD 5 - Testing Web Applications
- What we'll cover in this section
- Creating a simple web app
- Setting up a route and handler for the home page
- Testing our application routes
- Testing Handlers: the Home handler
- Setting up some simple middleware
- Trying out our new addIPToContext middleware
- Testing our middleware
- Testing ipFromContext
- Creating a login form
- Setting up a route and stub handler for the login form
UNIDAD 6 - Testing Validation · 5 leccionesUNIDAD 6 - Testing Validation
UNIDAD 6 - Testing Validation
- What we'll cover in this section
- Setting up validation logic
- Testing validation logic
- Completing the tests for our validation logic
- Trying out validation with our login form
UNIDAD 7 - Testing Sessions · 9 leccionesUNIDAD 7 - Testing Sessions
UNIDAD 7 - Testing Sessions
- What we'll cover in this section
- Setting up a test enviroment with testing.M
- Simplifying our templates using a layout
- Installing a sessions package
- Adding session to App config, and creating a SessionManager
- Trying out our sessions
- Updating our tests
- Improving our test for the Home handler
- Testing the render function with a bad template
UNIDAD 8 - Testing POST handlers · 14 leccionesUNIDAD 8 - Testing POST handlers
UNIDAD 8 - Testing POST handlers
- What we'll cover in this section
- Installing postgres with Docker
- Setting up a database connection
- Adding the data package for models and db package for database access
- Making sure our web app can connect to our database
- Closing our database pool gracefully, and resetting template path in tests
- Creating a stub profile page
- Adding messages to our template data and template files
- Adding true authentication to the Login handler
- Testing the Login handler
- Adding Auth middleware
- Testing Auth middleware
- Updating routes & end-to-end tests
- Problems with our Login handler test
UNIDAD 9 - The Repository Pattern · 7 leccionesUNIDAD 9 - The Repository Pattern
UNIDAD 9 - The Repository Pattern
- What we'll cover in this section
- Defining an interface type for our repository
- Moving our database functions into a repository
- Updating application config to use the database repository
- Creating a testdb repository
- Updating setup_test.go to use the test repository
- Updating our tests to use the testdb repository
UNIDAD 10 - Testing the database with Integration tests · 12 leccionesUNIDAD 10 - Testing the database with Integration tests
UNIDAD 10 - Testing the database with Integration tests
- What we'll cover in this section
- Getting started with testing our database
- Getting our tests to spin up a docker image with Postgres
- Populating our test database with empty tables
- Testing InsertUser
- Testing AllUsers
- Testing GetUser and GetUserByEmail
- Testing UpdateUser
- Testing DeleteUser
- Testing ResetUserPassword
- Testing InsertUserImage
- Using build tags to separate our integration tests
UNIDAD 11 - Testing File Uploads · 9 leccionesUNIDAD 11 - Testing File Uploads
UNIDAD 11 - Testing File Uploads
- What we'll cover in this section
- Adding a form to the Profile page
- Adding the UserImage type to the User type
- Updating the profile.page.gohtml file to look for a profile image
- Writing a stub handler and a function to process profile image uploads
- Implementing the UploadProfilePic handler
- Trying things out
- Testing image uploads
- Testing our upload handler, with an alternative approach
UNIDAD 12 - Testing REST APIs · 21 leccionesUNIDAD 12 - Testing REST APIs
UNIDAD 12 - Testing REST APIs
- What we'll cover in this section
- Setting up an api with our existing code base
- Adding stub handlers (endpoints) for our API
- Trying out our REST API to make sure things work
- Getting started with JWT Authentication
- Generating token pairs
- Implementing the authenticate handler
- Trying out the authentication handler
- Testing our authentication handler
- Setting up a simple program to generate tokens for testing
- Testing generating and validating tokens
- Setting up our application middleware
- Testing our CORS middleware
- Testing our authRequired middleware
- Add middleware to routes
- Testing API routes
- Implementing the handler to refresh tokens
- Testing refreshing tokens
- Completing the handlers that interact with the User type
- Testing the handlers that interact with the User type
- Finishing up testing handlers that interact with the data.User type
UNIDAD 13 - Testing an API for a Single Page Application (SPA) · 10 leccionesUNIDAD 13 - Testing an API for a Single Page Application (SPA)
UNIDAD 13 - Testing an API for a Single Page Application (SPA)
- What we'll cover in this section
- Serving HTML for our SPA
- Authenticating users with our SPA
- Setting a refresh token cookie when authenticating
- Allowing users to refresh tokens using a cookie
- Automatically refreshing tokens while the user is logged in
- Getting a user from our simple SPA with the "Get User" button
- Logging web users out
- Testing refreshing tokens for Single Page Apps
- Testing logging users out of our SPA
Tu certificado lo emite la SEP, no solo una plataforma
Al demostrar la competencia recibes un certificado emitido por la Secretaría de Educación Pública a través del Gobierno del Estado de México: un documento oficial que puedes presentar con confianza ante cualquier empleador o institución.
Tu certificado con INEC
- Lo emite la Secretaría de Educación Pública (SEP), a través del Gobierno del Estado de México
- Documento oficial con folio verificable en línea
- Lo otorga la Universidad Tecnológica Fidel Velázquez
Otras plataformas en línea
- Constancia privada emitida por la misma plataforma
- Solo acredita horas cursadas o asistencia
- Sin respaldo de una autoridad educativa
Tu itinerario, de la inscripción al certificado
- 1
Inscripción con pago único
Pagas $2,800 MXN una sola vez y entras de inmediato al curso.
- 2
Estudias a tu ritmo
13 unidades con videos, lecturas y actividades, disponibles 24/7 durante 12 meses.
- 3
Cuestionarios por unidad
Cuestionarios para comprobar lo aprendido.
- 4
Certificado
Emitido por la SEP a través del Gobierno del Estado de México, con folio verificable.
Un certificado oficial de la SEP
- Emitido por la Secretaría de Educación Pública (SEP), a través del Gobierno del Estado de México. No es una constancia privada: es un documento oficial, y ese respaldo marca la diferencia frente a otras plataformas en línea.
- Contenido impartido por Trevor Sawler.
- Folio y QR verificables para compartirlo con quien te contrate.
Empieza hoy, a tu ritmo
Un solo pago y acceso inmediato al curso completo durante 12 meses.
- 13 unidades · 120 lecciones · 60 h
- 12 meses de acceso
- Certificado emitido por la SEP (Gob. del Estado de México) con folio verificable
Sobre tu inscripción
¿Cómo es el pago?
Un solo pago de $2,800 MXN. No hay mensualidades ni cargos recurrentes.
¿Cuánto tiempo tengo acceso?
12 meses desde tu inscripción, 24/7, para avanzar a tu ritmo.
¿Quién imparte el contenido?
El curso es impartido por Trevor Sawler; INEC gestiona tu inscripción, evaluación y certificado.
¿Qué pasa cuando vence mi acceso?
Puedes renovar tu cuenta tú mismo desde la plataforma, sin trámites ni esperas.


