1
用途:在xtext/xtend上下文中運行參數化測試。xtext parameterized xtext runner
進度:到目前爲止,我已經完成了它的運行,但它在junit窗口中出現錯誤。
問題: 兩個測試的故障跟蹤和結果出現在最後的測試中,如下圖所示。 由紅筆標記的第一個測試是有些未解決的,並且不包含任何故障跡線。
下面是測試類:
@RunWith(typeof(Parameterized))
@InjectWith(SemanticAdaptationInjectorProvider)
@Parameterized.UseParametersRunnerFactory(XtextParametersRunnerFactory)
class CgCppAutoTest extends AbstractSemanticAdaptationTest {
new (List<File> files)
{
f = files;
}
@Inject extension ParseHelper<SemanticAdaptation>
@Inject extension ValidationTestHelper
@Parameters(name = "{index}")
def static Collection<Object[]> data() {
val files = new ArrayList<List<File>>();
listf("test_input", files);
val test = new ArrayList();
test.add(files.get(0));
return Arrays.asList(test.toArray(), test.toArray());
}
def static void listf(String directoryName, List<List<File>> files) {
...
}
var List<File> f;
@Test def allSemanticAdaptations() {
System.out.println("fail");
assertTrue(false);
}
}
ParameterizedXtextRunner(靈感來自這裏:https://www.eclipse.org/forums/index.php?t=msg&th=1075706&goto=1726802&):
class ParameterizedXtextRunner extends XtextRunner {
val Object[] parameters;
val String annotatedName;
new(TestWithParameters test) throws InitializationError {
super(test.testClass.javaClass)
parameters = test.parameters;
annotatedName = test.name;
}
override protected getName() {
return super.name + annotatedName;
}
override protected createTest() throws Exception {
val object = testClass.onlyConstructor.newInstance(parameters)
val injectorProvider = getOrCreateInjectorProvider
if (injectorProvider != null) {
val injector = injectorProvider.injector
if (injector != null)
injector.injectMembers(object)
}
return object;
}
override protected void validateConstructor(List<Throwable> errors) {
validateOnlyOneConstructor(errors)
}
最後XtextParametersRunnerFactory:
class XtextParametersRunnerFactory implements ParametersRunnerFactory {
override createRunnerForTestWithParameters(TestWithParameters test) throws InitializationError {
new ParameterizedXtextRunner(test)
}
}