Three ways:
First, your xargs way fails because you give dirname more than one pathname at a time. Instead, pass pathnames one by one to it:
find . -type f -name '*_test.go' -print0 | xargs -0 -r -I {} dirname {}
The -print0 with find and -0 with xargs passes the pathnames as a nul-delimited list instead of as a newline-delimited list. The -r option for xargs will make sure that dirname isn't run if there is no input from find.
If you know that your filenames do not contain embedded newlines:
find . -type f -name '*_test.go' | xargs -r -I {} dirname {}
Secondly, call a in-line shell script with find that runs dirname on the files one by one:
find . -type f -name '*_test.go' -exec sh -c '
for pathname do
dirname "$pathname"
done' sh {} +
Alternatively, don't call dirname but use a parameter substitution in the loop (quicker):
find . -type f -name '*_test.go' -exec sh -c '
for pathname do
printf "%s\n" "${pathname%/*}"
done' sh {} +
Thirdly, if you're using GNU find, use its -printf:
find . -type f -name '*_test.go' -printf '%h\n'
Lastly, if you are using zsh:
print -rC1 -- ./**/*_test.go(.ND:h)
The (.ND:h) glob modifier asks the previous globbing pattern to only expand to regular files (.), and to expand to nothing if there is no files matching the pattern (N, like nullglob in bash), and to also include hidden names (D, like dotglob in bash). The :h at the end causes the "head" of each matching pathname to be returned (i.e. the directory part of the pathname without the filename).
You could do something equivalent in bash with a loop like so:
shopt -s globstar nullglob dotglob
for pathname in ./**/*_test.go; do
if [[ -f $pathname ]] && [[ ! -h $pathname ]]; then
printf '%s\n' "${pathname%/*}"
fi
done