我正在尝试创建一个可以以编程方式运行的测试套件。(文档确实提到可以让 IDE 进行测试运行,但在我看来,将测试套件设置为具有自己的可运行单元的标准 Ceylon 模块似乎是一种更常规的方法。此外,文档没有没有说明如何以 IDE 方式实际执行此操作)。
所以,我正在使用createTestRunner函数创建一个TestRunner 。所述函数将TestSource s (' ') 的 Sequential 作为其第一个参数。是这种类型的别名:TestSource[]
TestSource
Module|Package|ClassDeclaration|FunctionDeclaration|Class<Anything,Nothing>|FunctionModel<Anything,Nothing>|String
这提示了一个问题:我想如何将我的测试提供给测试运行器?
对于初学者来说,似乎最容易将它们放在本地函数中,然后让测试运行程序以某种方式访问这些函数(未进一步指定)。由于别名中包含的一长串类型TestSource
似乎不包括实际的Functions,因此我尝试寻找最近的候选对象:FunctionDeclaration。
为了做出这样的函数声明,我首先不得不考虑我的测试包装函数实际上可能是什么样子。也许是这样的?
Anything myTests1 () {
// assert something!
return null;
}
void myTests2 () {
// assert some more things!
}
(顺便说一下,这些函数在类型上是等效的)
经过大量Ceylon Herd 审查后,我认为FunctionDeclaration
此类函数的 a 可以这样拼写:
// function name for function declaration:
LIdentifier funName = LIdentifier("myName");
// type of return value for function declaration:
UIdentifier returnTypeName1 = UIdentifier("Anything");
TypeNameWithTypeArguments returnTypeName2 = TypeNameWithTypeArguments(returnTypeName1);
BaseType returnType = BaseType( returnTypeName2 );
// type of parameters for function declaration:
Sequential<Parameter> parameters1 = []; // our test wrapper functions takes no arguments
Parameters parameters2 = Parameters( parameters1 );
Sequence<Parameters> parameterLists = [parameters2];
// the actual function declaration:
FunctionDeclaration myFunctionDeclaration = FunctionDeclaration(
funName,
returnType,
parameterLists
);
所以现在,我所要做的就是将它提供给createTestRunner
函数。我只需要放入myFunctionDeclaration
一个TestSource[]
:
TestSource myTestSource = myFunctionDeclaration;
TestSource[] mySourceList = [myTestSource];
TestRunner myTestRunner = createTestRunner(mySourceList);
但是第一行不起作用。myFunctionDeclaration
'FunctionDeclaration' 类型的类型根本不会作为TestSource
类型传递。为什么不?不是FunctionDeclaration
正确的 TestSource 类型吗?查看 的别名定义TestSource
,FunctionDeclaration
似乎就在可能的类型列表中:
Module|Package|ClassDeclaration|FunctionDeclaration|Class<Anything,Nothing>|FunctionModel<Anything,Nothing>|String
我在这里想念什么?