Home

Awesome

lambdacd-junit

A Clojure library to integrate Junit test reports in LambdaCD

Build Status

Usage

Example

to add unit and integration tests in a typical gradle based Java project you could do

(ns pipeline.steps
  (:require
    [clojure.java.io :as io]
    [lambdacd-git.core :as core]
    [lambdacd.steps.shell :as shell]
    [lambdacd-junit.core :as junit4]))
    
(def gradle-test-cmd "./gradlew clean test")

(def gradle-integration-test-cmd "./gradlew clean integrationTest")

(defn clone [args ctx]
  (core/clone ctx (:repo (:config ctx)) (:revision args) (:cwd args)))
  
(defn gradle-test [args ctx]
  (-> (shell/bash ctx (:cwd args) gradle-test-cmd)
      (junit4/junit4-reports args "/build/test-results/" "Unit Tests" [#"TEST-.*"])))

(defn gradle-integration-test [args ctx]
  (-> (shell/bash ctx (:cwd args) gradle-integration-test-cmd )
      (junit4/junit4-reports args "/build/test-results/" "Integration Tests" [#"TEST-.+IntegrationTest.*"])))

Screenshot

LambdaCD with test reports

JavaScript Example

this example is based on Jest (https://facebook.github.io/jest/) and Jest Junit (https://github.com/palmerj3/jest-junit). It should be easy to use different JavaScript testing tools as long as they are able to produce a junit report xml.

Jest and Jest Junit need to be properly setup according to their documentation.

(ns pipeline.steps
  (:require
    [clojure.java.io :as io]
    [lambdacd-git.core :as core]
    [lambdacd.steps.shell :as shell]
    [lambdacd-junit.core :as junit4]))
    
(def javascript-jest-test-cmd "JEST_JUNIT_OUTPUT='./artifacts/junit.xml' jest --ci --testResultsProcessor='jest-junit'")

(defn jest-test [args ctx]
	(-> (shell/bash ctx (:cwd args) javascript-jest-test-cmd)
		(junit4/junit4-reports args "/artifacts" "Jest Tests" [#"junit.xml"])))

Related projects

License

Copyright © 2016, 2017 Thilo Horstmann

Distributed under the Apache License 2.0