为Go应用程序创建TravisCI配置以进行自动化测试

huangapple go评论87阅读模式
英文:

Creating a TravisCI config for automated testing of a Go application

问题

我想创建一个.travis.yml配置文件,实现以下功能:

  • 从Github获取Go应用程序的源代码,
  • 使用go get安装其他所需的库,
  • 使用go build尝试构建Go应用程序,
  • 使用go test运行测试。

我对使用TravisCI进行Go应用程序测试还不熟悉,因此我会感激任何人能够给我提供帮助或示例。

英文:

I would like to create a .travis.yml config that performes the following:

  • fetches a Go application source code from Github,
  • installs the other required libraries with go get
  • attempts to build the go application with go build
  • run tests with go test

I new to Go application testing with TravisCI, therefore I would appreciate any help or examples someone could point me to.

答案1

得分: 0

  1. 在你的代码库根目录下添加一个.travis.yml文件;
  2. 将你的GitHub账号连接到TravisCI;
  3. 打开开关,使得在提交和拉取请求时运行构建。

以下是我在一些Gorilla工具包代码库中使用的配置:

language: go
sudo: false

matrix:
  include:
    - go: 1.2
    - go: 1.3
    - go: 1.4
    - go: 1.5
    - go: 1.6
    - go: tip

install:
  - go get golang.org/x/tools/cmd/vet

script:
  - go get -t -v ./...
  - diff -u <(echo -n) <(gofmt -d .)
  - go tool vet .
  - go test -v -race ./...

(来源: https://github.com/gorilla/csrf/blob/master/.travis.yml)

英文:
  1. Add a .travis.yml to the root of your repository;
  2. Connect your GitHub account to TravisCI
  3. Flick the switch to run builds on commits and pull requests.

Here's what I'm using for some of the Gorilla toolkit repos:

language: go
sudo: false

matrix:
  include:
    - go: 1.2
    - go: 1.3
    - go: 1.4
    - go: 1.5
    - go: 1.6
    - go: tip

install:
  - go get golang.org/x/tools/cmd/vet

script:
  - go get -t -v ./...
  - diff -u <(echo -n) <(gofmt -d .)
  - go tool vet .
  - go test -v -race ./...

(source: https://github.com/gorilla/csrf/blob/master/.travis.yml)

huangapple
  • 本文由 发表于 2016年2月27日 03:25:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/35660035.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定