Skip to content

Commit 0048b22

Browse files
ghaskinsecb
authored andcommitted
Add 'Testing' documentation
Signed-off-by: Greg Haskins <[email protected]>
1 parent def9ae6 commit 0048b22

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

doc/cljdoc.edn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
["Workflows" {:file "doc/workflows.md"}]
44
["Activities" {:file "doc/activities.md"}]
55
["Workers" {:file "doc/workers.md"}]
6-
["Client" {:file "doc/client.md"}]]}
6+
["Client" {:file "doc/client.md"}]
7+
["Testing" {:file "doc/testing.md"}]]}

doc/testing.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Testing Your Workflows
2+
3+
## Overview
4+
5+
This Temporal Clojure SDK provides a test framework to facilitate Workflow unit-testing. The test framework includes an in-memory implementation of the Temporal service.
6+
7+
You can use the provided environment with a Clojure unit testing framework of your choice, such as `clojure.test`.
8+
9+
## Example
10+
11+
```clojure
12+
(ns my.tests
13+
(:require [clojure.test :refer :all]
14+
[taoensso.timbre :as log]
15+
[temporal.client.core :as c]
16+
[temporal.testing.env :as e]
17+
[temporal.workflow :refer [defworkflow]]
18+
[temporal.activity :refer [defactivity] :as a]))
19+
20+
(def task-queue "MyTaskQueue")
21+
22+
(defactivity greet-activity
23+
[ctx {:keys [name] :as args}]
24+
(log/info "greet-activity:" args)
25+
(str "Hi, " name))
26+
27+
(defworkflow greeter-workflow
28+
[ctx {:keys [args]}]
29+
(log/info "greeter-workflow:" args)
30+
@(a/invoke greet-activity args))
31+
32+
(deftest my-test
33+
(testing "Verifies that we can invoke our greeter workflow"
34+
(let [{:keys [client] :as env} (e/create {:queue-name task-queue})
35+
(c/create-workflow client greeter-workflow {:task-queue task-queue})]
36+
(c/start workflow {:name "Bob"})
37+
(is (= @(c/get-result workflow) "Hi, Bob")))))
38+
```
39+
40+
The primary difference between this test and a real-world application is the use of ([temporal.testing.env/create](https://cljdoc.org/d/io.github.manetu/temporal-sdk/CURRENT/api/temporal.testing.env#create)) function. This method simultaneously creates an instance of the in-memory Temporal service *and* a client already connected to this environment.
41+
42+
Typical tests may opt to create the testing environment within a [fixture](https://clojuredocs.org/clojure.test/use-fixtures), but this is left as an exercise to the reader. The testing environment may be cleanly shutdown with ([stop](https://cljdoc.org/d/io.github.manetu/temporal-sdk/CURRENT/api/temporal.testing.env#stop))

0 commit comments

Comments
 (0)