-
Notifications
You must be signed in to change notification settings - Fork 34
Test Structure
James Richford edited this page Jan 6, 2017
·
1 revision
Create your first spec file
import { Expect, Test } from "alsatian";
export class ExampleTestFixture {
@Test()
public exampleTest() {
Expect(1 + 1).toBe(2);
}
}
Then check all is well
> alsatian "./path/to/example.spec.js"
TAP version 13
1..1
ok 1 - exampleTest
By default, tests will be named the same as their functions and fixtures will be named the same as their class. This will be what is output by alsatian. However, you can give the test or fixture more meaningful name simply by supplying the Test
and TestFixture
annotations with whatever you desire.
import { Expect, Test, TestFixture } from "alsatian";
@TestFixture("Awesome Test Fixture")
export class ExampleTestFixture {
@Test("Confirm 1 + 1 is 2")
public test1() {
Expect(1 + 1).toBe(2);
}
}
Then check all is well
> alsatian ./path/to/example.spec
Awesome Test Fixture
Confirm 1 + 1 is 2
|====================|
Pass: 1/1
Fail: 0/1
Ignore: 0/1
You can pass arguments to your tests simply by using the TestCase
annotation
import { Expect, TestCase, TestFixture } from "alsatian";
@TestFixture("Example Test Fixture")
export class ExampleTestFixture {
@TestCase(1, 2)
@TestCase(4, 5)
public exampleTest(preIteratedValue: number, expected: number) {
Expect(preIteratedValue++).toBe(expected);
}
}