Skip to content

Instantly share code, notes, and snippets.

@HakShak
Created March 10, 2015 18:24
Show Gist options
  • Save HakShak/e4f7d78834d853a6cc89 to your computer and use it in GitHub Desktop.
Save HakShak/e4f7d78834d853a6cc89 to your computer and use it in GitHub Desktop.
GoLang TeamCity Test Output
package teamcity
import (
"fmt"
"runtime"
"strconv"
"time"
"testing"
)
type Test struct {
TestName string
StartTime time.Time
t *testing.T
}
func (t *Test) Finished() {
fmt.Printf("##teamcity[testFinished name='%s' duration='%d']\n", t.TestName, time.Since(t.StartTime)/time.Millisecond)
}
func (t *Test) Failed(message string, details string) {
fmt.Printf("##teamcity[testFailed name='%s' message='%s' details='%s']\n", t.TestName, message, details)
t.t.Fail()
}
type TestSuite struct {
TestSuiteName string
}
func TestSuitStarted(suiteName string) TestSuite {
fmt.Printf("##teamcity[testSuiteStarted name='%s']\n", suiteName)
testSuite := new(TestSuite)
testSuite.TestSuiteName = suiteName
return *testSuite
}
func (ts *TestSuite) TestSuitFinished() {
fmt.Printf("##teamcity[testSuiteFinished name='%s']\n", ts.TestSuiteName)
}
func TestStarted(t *testing.T, captureStandardOutput bool) Test {
test := new(Test)
test.t = t
pc, _, _, ok := runtime.Caller(1)
if !ok {
test.TestName = "unknown"
}
me := runtime.FuncForPC(pc)
if me == nil {
test.TestName = "unnamed"
}
if test.TestName == "" {
test.TestName = me.Name()
}
test.StartTime = time.Now()
fmt.Printf("##teamcity[testStarted name='%s' captureStandardOutput='%s']\n", test.TestName, strconv.FormatBool(captureStandardOutput))
return *test
}
func TestIgnored(testName string, message string) {
fmt.Printf("##teamcity[testIgnored name='%s' message='%s']\n", testName, message)
}
func TestStdOut(testName string, out string) {
fmt.Printf("##teamcity[testStdOut name='%s' out='%s']\n", testName, out)
}
func TestStdErr(testName string, out string) {
fmt.Printf("##teamcity[testStdErr name='%s' out='%s']\n", testName, out)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment