Golang run test cases of few files not whole project – Code Example


To run test cases in golang for the whole project, you can use go test <package_name>. But if you want to run test cases of few files, you will need -run flag. This flag will pick those test files which will match the providing regex.

Solution with Code Example

go test packageName -run test_name

This will run all the tests which contains string test_name in their name. To restrict it to exactly this name, use can use regex –

go test packageName -run "^test_name$"