Table tests are a great way to test different inputs and associated outputs for a function in Go. To write a table test, you define a slice of some data struct with fields of the input data you’ll need and the expected outcome. Then you can loop through this slice and pass the data stored for each element to your function. One disadvantage of table tests is as the data set in your slice grows, the harder it is to find the failing case. Luckily, Miki will share some tips to manage this with the Go test suite.
In this video, Miki has a large set of input data to test. Miki will write sub-tests to make it easier to identify a failing case. To execute a sub-test, Miki will invoke the Run method from the testing.T parameter provided to every test function. During invocation, he’ll pass a test name and a function with test logic to execute. If the test fails, the test name Miki passed earlier is displayed on the console making it easier to find the failing case. Watch and learn how to add sub tests to your code.
Things you will learn in this video
From the Ardan Community
Get your team up to date with best practices & customized curriculum.
We help you evaluate your architecture, design, structure, tech-debt and human capital.
Learn at your own pace!
Special offers on upcoming training events & our latest blog posts.
Valid email required.
Submit failed. Try again or message us directly at email@example.com.
Check your email for confirmation.
We've built our reputation as educators and bring that mentality to every project. When you partner with us, your team will learn best practices and grow along the way.
Years in Business
Please fill out the form below, and we'll get back to you soon.
Check your email for confirmation of your sent message. We'll get back to you shortly.
Ardan Labs Copyrights © 2023