繁体   English   中英

尝试使用Citrus-编译错误:需要返回类型

[英]Trying to use Citrus - Compilation error: return type required

我在尝试遵循“ 5.3。Java DSL测试设计器”一章中的柑橘示例时遇到错误( https://citrusframework.org/citrus/reference/2.7.8/html/index.html#java-dsl-test-设计器 ),这是LoggingTestDesignerRightOrder.java中的代码

package com.consol.citrus.samples;

import org.testng.annotations.Test;
import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;
import com.consol.citrus.TestAction;
import com.consol.citrus.context.TestContext;
import com.consol.citrus.actions.AbstractTestAction;
import com.consol.citrus.samples.LoggingService;

@Test
public class LoggingTestDesignerRightOrder extends     TestNGCitrusTestDesigner {
private LoggingService loggingService = new LoggingService();

@CitrusTest(name = "LoggingTestRightOrder")
public void loggingTest() {
    echo("Before loggingService call");

   action(new AbstractTestAction() {
        doExecute(TestContext context) {
           loggingService.log("Now called custom logging service");
        }
    });

    echo("After loggingService call");
    }
}

运行mvn clean时,请验证-Dit.test = LoggingTestDesignerRightOrder

我收到以下错误:

无法在项目citrus-sample上执行目标org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile(default-testCompile):编译失败[ERROR] / Users / fb / dev / citrus / citrus- sample / src / test / java / com / consol / citrus / samples / LoggingTestDesignerRightOrder.java:[20,13]无效的方法声明; 需要返回类型

我可以看到这是创建pb的doExecute调用,但找不到使其进行编译所需的内容。

mvn命令的完整输出:

Scanning for projects...
[INFO] 
[INFO] --------------< com.consol.citrus.samples:citrus-sample >---------------
[INFO] Building Citrus Integration Test 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ citrus-sample ---
[INFO] Deleting /Users/fb/dev/citrus/citrus-sample/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ citrus-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ citrus-sample ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ citrus-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) @ citrus-sample ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to /Users/fb/dev/citrus/citrus-sample/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/fb/dev/citrus/citrus-sample/src/test/java/com/consol/citrus/samples/LoggingTestDesignerRightOrder.java:[20,13] invalid method declaration; return type required
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.150 s
[INFO] Finished at: 2018-12-22T21:54:19+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile (default-testCompile) on project citrus-sample: Compilation failure
[ERROR] /Users/fb/dev/citrus/citrus-    sample/src/test/java/com/consol/citrus/samples/LoggingTestDesignerRightOrder.java:[20,13] invalid method declaration; return type required
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]   http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

谢谢您的帮助。

听编译器:)

...LoggingTestDesignerRightOrder.java:[20,13] invalid method declaration; return type required

是由第20行中的匿名AbstractTestAction实现引起的。 至少缺少正确的返回类型。

您的实现需要正确地覆盖doExecute方法,如下所示:

action(new AbstractTestAction() {
    @Override
    public void doExecute(TestContext context) {
        loggingService.log("Now called custom logging service");
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM