• Modules
    • By category
    • By name
    • Most popular
    • Most downloaded
    • Repository
  • Register
  • Log in
  • Help
    • Start using Ceylon Herd
    • Publish your first module
    • Module publishing guidelines
    • All about Ceylon
    • Keyboard Shortcuts

    • s Focus search module bar
      ? Open this information panel
      j Move selection down
      k Move selection up
      enter Open current selection
Module info
Name
FroMage / ceylon.test / 1.2.1-1
Ceylon Test Platform Module
Category SDK

The Ceylon SDK

Backends JVM JavaScript
Maven coordinates
Compatible Ceylon release JVM: 1.2.x, 1.3.x (latest)
JavaScript: 1.2.1, 1.2.2, 1.3.x (latest)
Published Feb 15, 2016
Stats Downloads (JVM): 368
Downloads (JS): 77
Source downloads: 438
Authors Tomáš Hradec
Tom Bentley
License Apache Software License
Description

The ceylon.test module is a simple framework to write repeatable tests.

Tests execute the code of the module under test and can make assertions about what it does. For example,

  • do functions, when called with certain arguments, return the expected results?
  • do classes behave as required?
  • etc.

GETTING STARTED

Tests can be written as top level functions …

test
void shouldAlwaysSucceed() {}

… or organized inside classes.

class YodaTest() {

    test
    void shouldBeJedi() {
        assert(yoda is Jedi);
    }

    test
    void shouldHavePower() {
        assert(yoda.midichloriansCount > 1k);
    }

(notice the test annotation, which helps the framework to discover tests)


ASSERTIONS

Assertions can be evaluated by using the language's assert statement or with the various assert... functions, for example:

assert(is Hobbit frodo);
assert(exists ring);

assertNotEquals(frodo, sauron);
assertThatException(() => gandalf.castLightnings()).hasType(`NotEnoughMagicPowerException`);

A test function which completes without propagating an exception is classified as a success. A test function which propagates an AssertionError is classified as a failure. A test function which propagates any other type of Exception is classified as an error.


HOOKS

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();

Other options how to hook into tests execution, is to implement TestListener and react on concrete events. Or if you have to go deeper, there are several ceylon.test.engine.spi::TestExtension points.


DISABLING TESTS

Sometimes you want to temporarily disable a test or a group of tests, this can be done via the ignore annotation.

test
ignore("still not implemented")
void shouldBeFasterThanLight() {

Sometimes the conditions, if the test can be reliable executed, are know only in runtime, in that case one of the assume... functions can be used.


RUNNING

The most convenient way how to run tests is to use IDE integration or via command line tools ceylon test and ceylon test-js.

$ceylon test com.acme.mymodule

Tests can be also run programmatically, via interface TestRunner and its factory method createTestRunner, but this API is usually not necessary to use directly.


Dependencies
All backends JVM JavaScript
ceylon.collection/1.2.1
ceylon.language/1.2.1
ceylon.file/1.2.1
ceylon.runtime/1.2.1
java.base/7 JDK
org.jboss.modules/1.4.4.Final
Usage
  • Import
 import ceylon.test "1.2.1-1";
Module links Members
Imported By
Home
Code repository
Issue tracker
Browse
Download .car
Download .js
Download source archive
Download module documentation
View API documentation

Ceylon Herd v1.24 Copyright 2012-2022 Red Hat. About