Produce Sponge-compatible test result output.

Change-Id: I60883797af75c8e680324c386ded31c47e2e9cc3
Reviewed-on: https://code-review.googlesource.com/c/37991
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jean de Klerk <deklerk@google.com>
diff --git a/go.mod b/go.mod
index 273ca54..fac3c11 100644
--- a/go.mod
+++ b/go.mod
@@ -9,6 +9,7 @@
 	github.com/google/martian v2.1.0+incompatible
 	github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57
 	github.com/googleapis/gax-go/v2 v2.0.3
+	github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024
 	go.opencensus.io v0.18.0
 	golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d
 	golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3
diff --git a/go.sum b/go.sum
index abc79c4..25c4a3a 100644
--- a/go.sum
+++ b/go.sum
@@ -45,6 +45,8 @@
 github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
 github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
 github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
+github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024 h1:rBMNdlhTLzJjJSDIjNEXX1Pz3Hmwmz91v+zycvx9PJc=
+github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
 github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
 github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
diff --git a/internal/kokoro/continuous.sh b/internal/kokoro/continuous.sh
index dd60ecc..31a3cca 100755
--- a/internal/kokoro/continuous.sh
+++ b/internal/kokoro/continuous.sh
@@ -43,5 +43,13 @@
 
 ./internal/kokoro/vet.sh
 
+# TODO(deklerk): Remove once tools are installed via tools.go.
+go get github.com/jstemmer/go-junit-report
+
 # Run tests and tee output to log file, to be pushed to GCS as artifact.
-go test -race -v -timeout 30m ./... 2>&1 | tee $KOKORO_ARTIFACTS_DIR/$KOKORO_GERRIT_CHANGE_NUMBER.txt
+# Also generate test summary in xUnit format to summarize the test execution.
+mkdir $KOKORO_ARTIFACTS_DIR/tests
+go test -race -v -timeout 30m ./... 2>&1 \
+  | tee $KOKORO_ARTIFACTS_DIR/$KOKORO_GERRIT_CHANGE_NUMBER.txt \
+  | go-junit-report >$KOKORO_ARTIFACTS_DIR/tests/sponge_log.xml
+
diff --git a/internal/kokoro/presubmit.sh b/internal/kokoro/presubmit.sh
index 08545ed..fc5c375 100755
--- a/internal/kokoro/presubmit.sh
+++ b/internal/kokoro/presubmit.sh
@@ -34,5 +34,13 @@
 
 ./internal/kokoro/vet.sh
 
+# TODO(deklerk): Remove once tools are installed via tools.go.
+go get github.com/jstemmer/go-junit-report
+
 # Run tests and tee output to log file, to be pushed to GCS as artifact.
-go test -race -v -timeout 15m -short ./... 2>&1 | tee $KOKORO_ARTIFACTS_DIR/$KOKORO_GERRIT_CHANGE_NUMBER.txt
+# Also generate test summary in xUnit format to summarize the test execution.
+mkdir $KOKORO_ARTIFACTS_DIR/tests
+go test -race -v -timeout 15m -short ./... 2>&1 \
+  | tee $KOKORO_ARTIFACTS_DIR/$KOKORO_GERRIT_CHANGE_NUMBER.txt \
+  | go-junit-report >$KOKORO_ARTIFACTS_DIR/tests/sponge_log.xml
+
diff --git a/tools.go b/tools.go
index 8f61430..5c91f8a 100644
--- a/tools.go
+++ b/tools.go
@@ -25,6 +25,7 @@
 
 import (
 	_ "github.com/golang/protobuf/protoc-gen-go"
+	_ "github.com/jstemmer/go-junit-report"
 	_ "golang.org/x/lint/golint"
 	_ "golang.org/x/tools/cmd/goimports"
 	_ "honnef.co/go/tools/cmd/staticcheck"