Name |
Ceylon Test Platform Module |
---|---|
Category |
SDK
The Ceylon SDK |
Backends | JVM JavaScript |
Maven coordinates | |
Compatible Ceylon release |
JVM: 1.0.0 (outdated) JavaScript: 1.0.0 (outdated) |
Published | Nov 11, 2013 |
Stats |
Downloads (JVM): 1273 Downloads (JS): 305 Source downloads: 1120 |
Authors |
Tomáš Hradec Tom Bentley |
License | Apache Software License |
Description |
The Tests execute the code of the module under test and can make assertions about what it does. For example,
The usual way to use this module is to write your tests (which make
calls to the declarations under test) as top level functions or
as methods of top level classes, annotating them with For example, here is a trivial test void shouldAlwaysSucceed() {} Assertions can be evaluated by using the language's assert(is Hobbit frodo); assert(exists ring); assertNotEquals(frodo, sauron); assertThatException(() => gandalf.castLightnings()).hasType(`NotEnoughMagicPowerException`); It's also perfectly acceptable to throw [[AssertionException]] directly. A test function which completes without propogating an exception is
classified as a Test functions can be grouped together inside a class. class YodaTest() { test void shouldBeJedi() { assert(yoda is Jedi); } test void shouldHavePower() { assert(yoda.midichloriansCount > 1k); } Common initialization logic can be placed into separate functions, which run before or after each test. class StarshipTest() { beforeTest void init() => starship.chargePhasers(); afterTest void dispose() => starship.shutdownSystems(); Sometimes you want to temporarily disable a test or a group of tests,
this can be done via the test ignore("still not implemented") void shouldBeFasterThanLight() { Tests can be run programmatically for a whole module, a package or only
individual classes and functions. This is usually achieved using the
value result = createTestRunner([`module com.acme`]).run(); print(result.isSuccess); Or by enumerating the things to be tested: value result = createTestRunner([ `shouldBeFasterThanLight`, `StarshipTest`]).run(); print(result.isSuccess); Although you can implement the [[TestRunner]] interface directly,
Using listeners you can react to important events during test execution, or you can exclude particular tests, or execute them in a specific order. object ringingListener satisfies TestListener { shared actual void testError(TestResult result) => alarm.ring(); } Boolean integrationTestFilter(TestDescription d) { return d.name.endsWith("IntegrationTest"); } Comparison failFastComparator(TestDescription d1, TestDescription d2) { return dateOfLastFailure(d1) <=> dateOfLastFailure(d2); } TestRunner runner = createTestRunner{ sources = [`module com.acme`]; listeners = [ringingListener]; filter = integrationTestFilter; comparator = failFastComparator; }; |
Usage |
import ceylon.test "1.0.0"; |
Module links |
Members Imported By Home Code repository Issue tracker Browse Download .car Download .js Download source archive Download module documentation View API documentation |