Skip to content
DannoHung edited this page Sep 13, 2010 · 9 revisions

Fixtures provide a convenient and simple way of getting data into your tests without cluttering the test code with a bunch of literals. There are three distinct types of fixtures that can be used:

  • A Q object saved to disk as a file
  • A directory containing splays and/or partitioned tables
  • A specially formatted separated value file (like a csv, but slightly different)

There are two methods used for loading fixtures that are closely related:

fixture and fixtureAs

fixture is a function which takes one argument: A symbol specifying the name of the fixture to be loaded. This will cause the fixture specified by that name to be loaded into the current namespace as the name specified if the fixture is a Q object file or a separated value file. If the fixture is a directory containing splayes or partitioned tables, then the directory will be loaded as if the \l directive was used with the directory path.

So, for example, supposing we have three different fixtures: foo, bar and baz. foo is a Q object file, bar is a separated value file, and baz is a directory:


q)fixture `foo
`foo
q)foo
1 2 3 4 5
q)fixture `bar
`bar
q)bar
a b
---
1 3
2 4
3 5
q)\a
,`bar
q)fixture `baz
`baz
q)\a
`bar`trade`quote

Please note that for this example and others on this page, we are ignoring that you would need to have written a test to actually be able to use the functions presented. To see a more concrete example of this feature, please see the Tutorial

fixtureAs is a function which takes two arguments: The first argument is the name of the fixture to be loaded and the second argument is a name to assign the fixture to as opposed to the default. If the fixture is a directory, the second argument is ignored.

Two paths are searched for fixtures: the directory where the test file was loaded from and a directory fixtures in the directory where the test file was loaded from if available. So, for example, if you were loading a fixture trade, you could have a test in /abc/def and both /abc/def and /abc/def/fixtures would be searched for the fixture.

Q File Object Fixtures

Directory Fixtures

Separated Value File Fixtures

Clone this wiki locally