Home >Backend Development >Golang >How Can I Skip Test Files in Go 1.4 and Below?

How Can I Skip Test Files in Go 1.4 and Below?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-11 15:40:21194browse

How Can I Skip Test Files in Go 1.4 and Below?

Skipping Test Files with Go 1.4 and Below

You have a test file that requires features available only in Go 1.5 and later, but it fails on systems running Go 1.4 and below. Despite attempting to use "// build go1.5" at the beginning of the file, it was unsuccessful.

The correct solution is to use build constraints. However, it's important to note that your error messages mention the http2 package, which was introduced in Go 1.6. Therefore, you need a build constraint of "go1.6" or higher.

To limit the test file to being built and tested only on Go 1.6 systems, add the following line near the top of the file, preceded only by blank lines and other line comments:

// +build go1.6

Remember that build constraints should be followed by a blank line to separate them from the package documentation.

A sample code:

// +build go1.6

package yourpackage

With this constraint, the test file will only be compiled and executed on Go 1.6 and above systems, skipping it on systems running Go 1.4 and below. This should resolve your CI build failures.

The above is the detailed content of How Can I Skip Test Files in Go 1.4 and Below?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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