Skip to content

Instantly share code, notes, and snippets.

@weissjeffm
Created November 24, 2010 15:09
Show Gist options
  • Save weissjeffm/713780 to your computer and use it in GitHub Desktop.
Save weissjeffm/713780 to your computer and use it in GitHub Desktop.
Example of running clojure code as testng tests
(ns test-clj.sample-tests
(:use [test-clj.meta :only [gen-class-testng]]))
;sample tests
;------------------------------
(defn ^{:test {:configuration :beforeSuite
:groups #{:group1 :group2}}}
config1 [_]
(do (println "running configuration1")
(println "configuration1 complete.")))
(defn ^{:test {:groups #{:group2 :group3}}}
test2 [_]
(do(println "running test2")
(println "test2 complete")))
(defn ^{:test {:groups #{:group1 :group2}
:dependsOnTests #'test2}}
test1 [_]
(do (println "running test1")
(println "test1 complete")))
(defn ^{:test {:groups #{:group2 :group3}
:dependsOnTests #'test2}}
test3 [_]
(do (println "running test3")
(throw (RuntimeException. "test failed!"))
(println "test3 complete")))
(defn ^{:test {:groups #{:group1 :group3}
:dependsOnTests #'test3}}
test4 [_]
(do (println "running test4")
;;(throw (RuntimeException. "test failed!"))
(println "test4 complete")))
(defn ^{:test {:groups #{:group1 :group2}
:configuration :beforeTest}}
config5 [_]
(do (println "running configuration5")
(println "configuration5 complete")))
(defn ^{:test {:groups #{:group1 :group2}
:configuration :afterTest}}
config6 [_]
(do (println "running configuration6")
(println "configuration6 complete")))
;end sample tests
;--------------------------------
(gen-class-testng)
(comment "TestNG output"
"
[jweiss@blinky test-clj]$ java org.testng.TestNG -testclass test_clj.sample_tests
[TestNG] Running:
Command line suite
running configuration1
configuration1 complete.
running configuration5
configuration5 complete
running test1
test1 complete
running configuration6
configuration6 complete
running configuration5
configuration5 complete
running test2
test2 complete
running configuration6
configuration6 complete
running configuration5
configuration5 complete
running test3
running configuration6
configuration6 complete
running configuration5
configuration5 complete
running test4
test4 complete
running configuration6
configuration6 complete
===============================================
Command line suite
Total tests run: 4, Failures: 1, Skips: 0
===============================================
[jweiss@blinky test-clj]$
"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment