JuliaLang/julia — pull request #1483 by jacg (2012-10-31 21:15:01+00:00)
Title: RFC: YouTest: Exploring test framework interfaces

A proof-of-concept testing framework, exploring test-specification interfaces.

Brief description of interface:

One test:

@test 1==1

One named test

@test "equality" 1==1

One named test that is expected expected to throw KeyError

@test "Dict lookup failure" {1=>2}[2] throws := KeyError

A named group of tests: each test has a name composed of the group name and its own individual name:

@test begin
"Commute"
"+"; a+b == b+a
"*"; a*b == b*a
end

Fixtures; four separate tests, each initialized with `d := {1=>2}`:

@test begin
"Dict"
setup := d = {1=>2}
d[1] == 2
d[2]; throws := KeyError
has(d, 1)
!has(d,2)
end

Multi-line test:

@test begin
single
d = {1=>2}
@check length(d) == 1
d[8] = 3
@check length(d) == 2
del(d,10)
length(d) == 1
end

Repeat the same (four) tests with different data:

@test begin
parametrize := ((a,b),
(1,2),
(3,4),
(5,6))
a+b == b+a
a-b == b-a; fails
a*b == b*a
a/b == b/a; fails
end

Skipping tests:

@test begin
"New feature X"
skip := version() < (2,4)
foo()
bar()
baz()
end

Explained in more detail in the README.md file.

The code runs, though only very basic test runners are provided.

The framework is pluggable, so adding new features should be very easy in many cases.