Search code examples
ceylon

How to make TestRunner pull tests from a separate class


I currently have a TestRunner (from ceylon.test) that can take tests from local functions. Now I'm trying to make it discover tests embedded in a class written in a separate file. However, the TestRunner does not find the test from the class, and I don't know how to debug this. There are no compiler errors. How do I begin debugging this problem?

This is the file+folder structure of the relevant files:

source/
 - designs/
  - BoundedPlane_test.ceylon
  - module.ceylon
  - package.ceylon
 - tests/
  - module.ceylon
  - package.ceylon
  - run.ceylon

Here's the content of each file:

designs/BoundedPlane_test.ceylon:

import ceylon.test {
    test
}

shared class BoundedPlane_test() {
    print("BoundedPlane_test class");

    test
    void shouldBeJedi() {
        print("jedi");
        assert(2 == 2);
    }
}

designs/module.ceylon:

native ("jvm")
module designs "1.0.0" {
    import ceylon.test "1.3.3.1";
    shared import ceylon.json "1.3.3";
    shared import gcode "1.0.0";
    import utils "1.0.0";
}

designs/package.ceylon:

shared package designs;

tests/module.ceylon:

native ("jvm")
module tests "1.0.0" {
    import ceylon.test "1.3.3.1";
    import ceylon.math "1.3.3";
    import designs "1.0.0";
}

tests/package.ceylon:

shared package tests;

tests/run.ceylon:

import ceylon.test {
    test, TestRunner, createTestRunner
}
import designs {
    BoundedPlane_test
}

test
Anything myTests1 () {
    // assert something true!
    assert(40 + 2 == 42);
    print("myTests1");
    return null;
}

test
void myTests2 () {
    // assert something false!
    assert(2 + 2 == 54);
    print("myTests2");
}


"Run the module `tests`."
shared void run() {

    print("reached run function");

    TestRunner myTestRunner = createTestRunner(
        [`function myTests1`, `function myTests2`, `class BoundedPlane_test`]);

    print( myTestRunner.run() );
}

Here's the output of executing the run function from tests/run.ceylon:

TEST RESULTS
run:      2
success:  1
failure:  1
error:    0
skipped:  0
aborted:  0
excluded: 0
time:     0s

tests::myTests2 - failure (ceylon.language.AssertionError "Assertion failed
    violated 2 + 2 == 54
        left-hand expression is 4
        right-hand expression is 54")

TESTS FAILED !

There are three assertions in total, but only two fo them gets recognized by the TestRunner. Those are the two tests from tests/run.ceylon. Notice that neither of the print statements from BoundedPlane_test.ceylon gets printed.


Solution

  • It works when I make that class-embedded test shared :

    test
    shared void shouldBeJedi() {
        print("jedi");
        assert(2 == 2);
    }