How to test one page in Go.

Tomoharu Tsutsumi
1 min readMay 18, 2024

There might be better ways.

Hi, I’ve recently joined a company using Go. One day, I tried to test one page in Golang. For example, let’s say that there are three Go test pages such as A_test.go, B_test.go and C_test.go. Besides, each file refers to corresponding types like AAA, BBB and CCC in them. If you want to test only A_test.go, can you do ‘go test A_test.go’?

No we can’t

The test will show you an error like

undefined: AAA

What should we do to solve this error?

The solution

The solution is making the test read the file defining AAA like…

go test A.go A_test.go // A.go is defining AAA

However, it looks a little inconvenient for me… We have to make it read every file including types which are necessary for the test…

Feel free to reach out to me on LinkedIn, which you can find below. Looking forward to connecting!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

Tomoharu Tsutsumi

Senior Software Engineer at two industry-leading startups ( Go | Ruby | TypeScript | JavaScript | Gin | Echo | Rails | React | Redux | Next)