Skip to content

Commit

Permalink
show skiped test in summary
Browse files Browse the repository at this point in the history
  • Loading branch information
vganshin committed Sep 16, 2019
1 parent eb7f357 commit f2f6ec7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
56 changes: 43 additions & 13 deletions src/runner.clj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
(if (empty? errs)
(do
(i conf (println (colors/green "passed")))
step)
(assoc step :status "passed"))
(do
(i conf (println (colors/red "failed")))
(pprint/pretty {:ident 0 :path [] :errors errs} resp)
Expand All @@ -117,6 +117,11 @@
:resp resp))))
(assoc step :failed? true :message "Cannot create requrest")))))

(comment

(exec-step {:conf {:url "http://ya.ru"} :steps []} {:GET "/"})

)
(defn get-id [test-case]
(or (:id test-case) (:filename test-case)))

Expand Down Expand Up @@ -173,11 +178,30 @@
:id #(if (nil? %) filename %))))

(defn run-file [{conf :conf test-cases :test-cases :as ctx} filename]
(println)
(let [test-case (read-test-case filename)]
(when (valid? ctx test-case)
(let [result (run-test-case conf test-case)]
(update ctx :test-cases #(conj % result))))))

(comment

)

(defn sum-for-test-case [{:keys [steps]}]
{:passed-tests (count (filter #(-> % :status (= "passed")) steps))
:failed-tests (count (filter #(-> % :status (= "failed")) steps))
:skipped-tests (count (filter #(-> % :status (= "skipped")) steps))
})


(defn sum-for-test-cases [test-cases]
(reduce #(fn [a b] {:passed-tests (+ (:passed-tests a) (:passed-tests b))
:failed-tests (+ (:failed-tests a) (:failed-tests b))
:skipped-tests (+ (:skipped-tests a) (:skipped-tests b))})
(map sum-for-test-case test-cases)
))

(defn get-summary [{test-cases :test-cases}]
(let [failed-tests (filter :failed? test-cases)
passed-tests (filter #(-> % :failed? not) test-cases)]
Expand All @@ -189,27 +213,33 @@

(defn run [conf files]
(let [result (reduce run-file {:conf conf :test-cases []} files)
sum (sum-for-test-cases (:test-cases result))
summary (get-summary result)
passed? (zero? (:count-failed-tests summary))]

(println)
(if passed?
(println "All" (:count-all-tests summary) "passed.")
(do
(println (:count-passed-tests summary) "passed,"
(:count-failed-tests summary) "failed.")
(println "Failed tests:")
(doseq [test-case (filter :failed? (:test-cases result))]
(println (:id test-case) (str "(" (:filename result) ")")))))

#_(clojure.pprint/pprint result)
(assoc result :passed? passed?)))
(println "Test results:" (:passed-tests sum) "passed,")
(println " " (:failed-tests sum) "failed,")
(println " " (:skipped-tests sum) "skipped.")

(vv conf (clojure.pprint/pprint result))
(assoc result :passed? (zero? (:failed-tests sum)))))

(comment

(run-file {:base-url "http://ya.ru"} "test/ya.yaml")

(run {:interactive false :verbosity 1 :base-url "http://main.aidbox.app" :client-id "wow" :client-secret "pass"} ["test/sample.yaml"])
(def r (run {:interactive false :verbosity 1 :base-url "http://main.aidbox.app" :client-id "wow" :client-secret "pass"} ["test/sample.yaml"]))

(def steps (-> r
:test-cases
first))

(clojure.pprint/pprint steps)

(sum-for-test-case steps)



(-> (run {:interactive false :verbosity 2 :base-url "http://localhost:8888" :basic-auth "cm9vdDpzZWNyZXQ="} [#_"test/w.yaml" "test/w.yaml"])
:failed))
4 changes: 3 additions & 1 deletion test/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ desc: Simple CRUD tutorial
steps:
- id: clean
desc: Clear all patients
only: true
POST: /$sql
body: 'TRUNCATE patient'
match:
Expand Down Expand Up @@ -60,6 +61,7 @@ steps:
match:
status: 200
- id: read-404
only: true
GET: /Patient/pt-1
match:
status: 404
status: 411

0 comments on commit f2f6ec7

Please sign in to comment.