Skip to content
Newer
Older
100644 86 lines (59 sloc) 2.62 KB
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
1 # xray
2
3 Heads up: This project is very much a work in progress.
4
5
6 ## Introduction
399ff64 @robwhitby remove unnecessary test function prefix
authored Dec 21, 2011
7 **xray** is a framework for testing XQuery on MarkLogic Server. Test cases are written as standard XQuery functions like this:
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
8
9 ```xquery
399ff64 @robwhitby remove unnecessary test function prefix
authored Dec 21, 2011
10 declare function string-equality-example()
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
11 {
12 let $foo := "foo"
13 return assert:equal($foo, "foo")
14 };
15 ```
16
17 ## Getting Started
18 * Copy xray into the root directory of your project
19 * Create an HTTP app server pointing to the root directory of your project.
20 * Check all is well at `http://server:port/xray/`
21 * Write some tests..
22
23
24 ## Writing Tests
399ff64 @robwhitby remove unnecessary test function prefix
authored Dec 21, 2011
25 Tests are grouped into library modules in the xray test namespace, importing the xray assertions module:
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
26
27 ```xquery
28 xquery version '1.0-ml';
29 module namespace test = 'http://github.com/robwhitby/xray/test';
30 import module namespace assert = 'http://github.com/robwhitby/xray/assertions' at '/xray/src/assertions.xqy';
31
399ff64 @robwhitby remove unnecessary test function prefix
authored Dec 21, 2011
32 declare function string-equality-example()
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
33 {
34 let $foo := "foo"
35 return assert:equal($foo, "foo")
36 };
37
399ff64 @robwhitby remove unnecessary test function prefix
authored Dec 21, 2011
38 declare function tests-can-contain-multiple-asserts()
39 {
40 let $foo := "foo"
41 let $bar := "bar"
42 return (
43 assert:not-empty($foo),
44 assert:equal($foo, "foo"),
45 assert:not-equal($foo, $bar)
46 )
47 };
48
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
49 (: more tests :)
50 ```
51
52 ## Invoking Tests
399ff64 @robwhitby remove unnecessary test function prefix
authored Dec 21, 2011
53 **xray** will find and execute all the test cases defined in a directory (and sub-directories), and can be told to execute a subset by specifying regex patterns to match tests by module name or test name.
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
54
399ff64 @robwhitby remove unnecessary test function prefix
authored Dec 21, 2011
55 * in browser - `http://server:port/xray/`
56 * command line - test-runner.sh is a sample shell script, edit default vars (tested on OSX only).
57 * invoke from xquery - import `src/xray.xqy` and call `xray:run-tests()`
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
58
59
399ff64 @robwhitby remove unnecessary test function prefix
authored Dec 21, 2011
60 ## Parameters
61 `dir` - test directory path relative from the app server modules root. Optional, defaults to 'test'.
62 `modules` - regex match on module name. Optional, default to match all.
63 `tests` - regex match on test name. Optional, defaults to match all.
64 `format` - set output format to html, xml or text. Optional, defaults to html.
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
65
66 ## Assertions
81ebb81 @robwhitby fixing links
authored Dec 21, 2011
67 See `src/assertions.xqy` for the current assertions.
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
68
69
70 ## Ignoring Tests
399ff64 @robwhitby remove unnecessary test function prefix
authored Dec 21, 2011
71 Not implemented yet.
72 Workaround - add `private` modifier to function.
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
73
74
75 ## Setup and teardown functions
399ff64 @robwhitby remove unnecessary test function prefix
authored Dec 21, 2011
76 `setup()` and `teardown()` are special function signatures. If defined, `setup()` is invoked before any tests in a seperate transaction, so any database updates are visible to the tests. `teardown()` is executed after all tests in that module have finished.
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
77
81ebb81 @robwhitby fixing links
authored Dec 21, 2011
78 See `test/tests.xqy` for an example.
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
79
80
81 ## Acknowledgements
9905170 @robwhitby Update README.md
authored Dec 21, 2011
82 Thanks to [John Snelson](http://github.com/jpcs) for the XQuery parser (part of https://github.com/xquery/xquerydoc). Without it I would still be hacking around with regexes.
6aaa8b7 @robwhitby tinkering with html output, added to readme
authored Dec 21, 2011
83
84
efd1a20 @robwhitby readme
authored Nov 13, 2011
85
Something went wrong with that request. Please try again.