Home > Backend Development > Golang > How Can I Run a Specific Test Within a Go Test Suite?

How Can I Run a Specific Test Within a Go Test Suite?

DDD
Release: 2024-12-13 18:47:15
Original
417 people have browsed it

How Can I Run a Specific Test Within a Go Test Suite?

Run Specific Tests in Go Test Suites

This question asks how to run a single test from a test suite in Go.

Answer:

To run a specific test from a Go test suite, use the -run flag of the go test command. The -run flag is documented in the testing flags section of the go tool documentation:

-run regexp
    Run only those tests and examples matching the regular
    expression.
Copy after login

For example, to run only the TestMyFunction test in the foo package:

go test -run 'TestMyFunction' ./foo
Copy after login

This is a convenient way to save time in the debugging process by re-running only the failed test.

The above is the detailed content of How Can I Run a Specific Test Within a Go Test Suite?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template