Concept Flow - Running tests
Write test function
Run 'go test'
Test framework executes test
Check test result
Report success
This flow shows how Go runs tests: you write test functions, run 'go test', it executes tests, then reports pass or fail.
package main import "testing" func TestAdd(t *testing.T) { if 2+2 != 4 { t.Error("2+2 should be 4") } }
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Run 'go test' | Find TestAdd function | TestAdd found |
| 2 | Execute TestAdd | Check if 2+2 == 4 | True |
| 3 | No error called | Test passes | Pass |
| 4 | Report result | Output test summary | PASS |
| Variable | Start | After Step 2 | Final |
|---|---|---|---|
| t.Error called | false | false | false |
| Test result | not run | running | pass |
Go tests are functions starting with Test. Run tests using 'go test' command. If t.Error or t.Fail is called, test fails. If no error, test passes by default. Test results are reported after execution.