繁体   English   中英

Maven 测试未使用自定义测试配置文件运行我的“@QuarkusTest”

[英]Maven test not running my `@QuarkusTest` with custom test profile

我注意到一个带有自定义测试配置文件的@QuarkusTest测试 class ,但是当我运行mvn test时,没有一个测试用例在运行 class 。 它们没有被跳过,没有被忽略,只是没有运行。 此测试有一个自定义测试配置文件,如下所示:

    /**
     * Create a test profile to provide config values only for this test
     */
    public static class EventSenderTestProfile implements QuarkusTestProfile {
        public EventSenderTestProfile() {

        }
        /**
         * Returns additional config to be applied to the test. This
         * will override any existing config (including in application.properties),
         * however existing config will be merged with this (i.e. application.properties
         * config will still take effect, unless a specific config key has been overridden).
         */
        public Map<String, String> getConfigOverrides() {
            return Map.of(
                    "prop1", "dummy",
                    "prop2", "dummy"
            );
        }

        /**
         * Returns enabled alternatives.
         *
         * This has the same effect as setting the 'quarkus.arc.selected-alternatives' config key,
         * however it may be more convenient.
         */
        public Set<Class<?>> getEnabledAlternatives() {
            return Collections.emptySet();
        }

        /**
         * Allows the default config profile to be overridden. This basically just sets the quarkus.test.profile system
         * property before the test is run.
         *
         */
        public String getConfigProfile() {
            return this.getClass().getName();
        }
    }

我正在使用 Java 11 和maven-surefire-plugin:3.0.0-M5

在 Intellij IDEA 中单独运行时,它们会运行并通过,但在 Maven 日志中:

[INFO] Running com.company.dep.app.event.sender.EventSenderTest
2022-09-02 13:17:41,724 INFO  [org.jbo.threads] (main) JBoss Threads version 3.4.2.Final
2022-09-02 13:17:42,600 WARN  [io.qua.mic.dep.bin.mpm.MicroprofileMetricsProcessor] (build-10) This application uses the MP Metrics API. The micrometer extension currently provides a compatibility layer that supports the MP Metrics API, but metric names and recorded values will be different. Note that the MP Metrics compatibility layer will move to a different extension in the future.
2022-09-02 13:17:43,095 INFO  [io.qua.arc.pro.BeanProcessor] (build-34) Found unrecommended usage of private members (use package-private instead) in application beans:
    - @Inject field com.company.dep.app.event.sender.EventSenderTest#eventSenderRestApi,
    - @Inject field com.company.dep.app.event.sender.EventSenderTest#appConfiguration,
    - @Inject field com.company.dep.app.event.acknowledgement.token2.SecurityInterceptor#resourceInfo
    - and 2 more - please enable debug logging to see the full list
2022-09-02 13:17:43,276 WARN  [io.qua.dep.ste.ClassTransformingBuildStep] (build-11) Cannot transform io.smallrye.context.Jdk12CompletableFutureWrapper as its containing application archive could not be found.
2022-09-02 13:17:43,293 WARN  [io.qua.dep.ste.ClassTransformingBuildStep] (build-11) Cannot transform io.smallrye.context.Jdk12CompletionStageWrapper as its containing application archive could not be found.
2022-09-02 13:17:47,593 WARN  [com.company.dep.app.eve.ack.tok.SecurityToken2Handler] (main) 
---------------------------------------------------------------------------
--------                                                              --------
----     !!! WARNING - RUNNING WITH LOCALLY AUTO-GENERATED KEY !!!     ----
--------                                                           --------
---------------------------------------------------------------------------
2022-09-02 13:17:47,905 INFO  [org.apa.cam.qua.cor.CamelBootstrapRecorder] (main) Bootstrap runtime: org.apache.camel.quarkus.main.CamelMainRuntime
2022-09-02 13:17:48,005 INFO  [com.company.dep.app.con.appConfiguration] (main) Configuration mapping initialized: 
2022-09-02 13:17:48,005 INFO  [com.company.dep.app.con.appConfiguration] (main) .....(configuration mappings)
2022-09-02 13:17:48,117 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Routes startup (total:2 started:2)
2022-09-02 13:17:48,117 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main)     Started route1 (activemq://queue:events)
2022-09-02 13:17:48,117 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main)     Started route2 (direct://receive.ack.response)
2022-09-02 13:17:48,117 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 3.14.1 (camel-1) started in 141ms (build:0ms init:126ms start:15ms)
2022-09-02 13:17:48,133 INFO  [com.company.dep.bas.log.depLogger] (main) Application is up
2022-09-02 13:17:48,134 INFO  [com.company.dep.bas.log.depLogger] (main) Application is up
2022-09-02 13:17:48,247 INFO  [com.company.dep.bas.shu.run.ShutdownController] (main) Setting pre shutdown sleep time to 0 seconds.
2022-09-02 13:17:48,248 INFO  [io.quarkus] (main) Quarkus 2.7.5.Final on JVM started in 17.066s. Listening on: http://localhost:8081
2022-09-02 13:17:48,249 INFO  [io.quarkus] (main) Profile com.company.dep.app.event.sender.EventSenderTest$EventSenderTestProfile activated. 
2022-09-02 13:17:48,249 INFO  [io.quarkus] (main) Installed features: [camel-activemq, camel-bean, camel-core, camel-direct, camel-jms, cdi, config-yaml, hibernate-validator, dep-shutdown-controller, jacoco, logging-json, micrometer, reactive-routes, rest-client, rest-client-jsonb, resteasy-reactive, resteasy-reactive-jsonb, security, smallrye-context-propagation, smallrye-fault-tolerance, smallrye-health, smallrye-jwt, smallrye-openapi, swagger-ui, vertx]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.739 s - in com.company.dep.app.event.sender.EventSenderTest

请注意,它们没有运行,但也没有跳过。

我有另一个没有自定义测试配置文件的@QuarkusTest 运行良好。

这是在同一测试中定义为 static class 的测试配置文件。 如果我将内部 class 移到另一个文件中,现在可以找到测试,但跳过了:

[WARNING] Tests run: 5, Failures: 0, Errors: 0, Skipped: 5, Time elapsed: 6.975 s - in com.company.dep.app.event.sender.EventSenderTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 5, Time elapsed: 6.975 s - in com.company.dep.app.event.sender.EventSenderTest

这是否意味着我不能在 Quarkus 测试中使用自定义测试配置文件?

并非所有测试都有效; 由于一些配置属性问题,一些@QuarkusTest无法启动。

好的,我想我找到了原因。 Quarkus 没有正确启动,因为发生了一些@ConfigMapping错误。 但是该测试未显示该错误,而仅在之前运行的其他@ConfigMapping测试中显示,并且该测试未标记为错误,而只是忽略为未跳过,未执行,未成功且未失败。

我看到了这个问题: https://github.com/quarkusio/quarkus/issues/12319 ,似乎是设计使然。 我必须说这是非常具有误导性的设计。

谷歌搜索“Maven 忽略我的 QuarkusTest”将我带到这个相关问题,其中提到了降级肯定插件,所以我打开-X maven 调试选项并在日志中搜索肯定。 我注意到,surefire 在target/surefire-reports中保存了一些报告,打开它们会将我带到这一行:

<testcase name="matchAndSendShouldReturnNullWhenNotMatching" classname="com.company.dep.app.event.sender.EventSenderTest" time="0">
    <skipped type="org.opentest4j.TestAbortedException">
        <![CDATA[ org.opentest4j.TestAbortedException: Boot failed ]]>
    </skipped>
...

搜索此异常导致我发现 github 问题。 谷歌拯救了另一个典型的程序员日。

解决方案:修复所有阻止 Quarkus 启动的引导错误,并且此测试通过。

暂无
暂无

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

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