Home > Backend Development > Golang > Why Does 'go test' Show 'no tests to run' Even With a Test Function?

Why Does 'go test' Show 'no tests to run' Even With a Test Function?

Barbara Streisand
Release: 2024-12-05 22:52:10
Original
497 people have browsed it

Why Does

Why "no tests to run" Despite Having a Test Function

Go testing requires a specific naming convention for test functions. The function name must begin with an uppercase letter "T" and follow the format TestXxx(t *testing.T).

In the provided code snippet, the test function is named testNormalizePhoneNum, which violates this convention. The testing tool ignores this function, resulting in the "no tests to run" message.

Solution:

To fix this issue, rename the test function to TestNormalizePhoneNum with an uppercase "T":

package main

import (
    "testing"
)

func TestNormalizePhoneNum(t *testing.T) {
    // ...
}
Copy after login

Alternative Solution:

Alternatively, you can force the testing tool to run the function by using the -run flag:

go test -run=testNormalizePhoneNum
Copy after login

However, this approach is not recommended as it bypasses the standard naming convention.

The above is the detailed content of Why Does 'go test' Show 'no tests to run' Even With a Test Function?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template