0
0
Goprogramming~5 mins

Test-driven basics in Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Test-Driven Development (TDD)?
TDD is a way to write software where you first write a test that fails, then write code to make the test pass, and finally clean up the code. It helps catch mistakes early and guides design.
Click to reveal answer
beginner
In Go, which package is commonly used for writing tests?
The testing package is used in Go to write tests. It provides tools to create test functions and check results.
Click to reveal answer
beginner
What is the typical order of steps in TDD?
1. Write a failing test.<br>2. Write code to pass the test.<br>3. Refactor the code.<br>4. Repeat.
Click to reveal answer
beginner
How do you name a test function in Go?
Test functions start with Test followed by a name, for example, TestAdd. They take a pointer to testing.T as a parameter.
Click to reveal answer
beginner
Why is writing tests first helpful?
Writing tests first helps you think about what your code should do before writing it. It makes your code clearer and reduces bugs.
Click to reveal answer
What is the first step in Test-Driven Development?
ARun the program
BWrite the full program
CRefactor the code
DWrite a failing test
Which Go package do you import to write tests?
Atesting
Bfmt
Cos
Dnet/http
How should a test function be named in Go?
AtestFunction
BFunctionTest
CTestFunction
DfunctionTest
What do you do after making a failing test pass in TDD?
AWrite more tests
BRefactor the code
CDelete the test
DRun the program without tests
Why is TDD useful?
AIt helps catch bugs early
BIt removes the need for comments
CIt makes coding slower
DIt avoids writing tests
Explain the three main steps of Test-Driven Development.
Think about the cycle of writing tests and code.
You got /3 concepts.
    Describe how to write a simple test function in Go using the testing package.
    Remember the naming and parameter rules for Go tests.
    You got /3 concepts.