首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maven测试没有使用自定义测试配置文件运行我的`@QuarkusTest`‘

Maven测试没有使用自定义测试配置文件运行我的`@QuarkusTest`‘
EN

Stack Overflow用户
提问于 2022-09-02 10:28:44
回答 1查看 188关注 0票数 0

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

代码语言:javascript
复制
    /**
     * 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中单独运行时,它们会运行并传递,但是在Maven日志中:

代码语言:javascript
复制
[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。运行得很好。

它是一个测试概要文件,定义为同一测试中的静态类。如果我将内部类移出到另一个文件,那么现在可以找到测试,但是跳过了:

代码语言:javascript
复制
[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无法启动。

EN

回答 1

Stack Overflow用户

发布于 2022-09-02 12:58:36

好吧,我想我知道原因了。Quarkus没有正确启动,因为发生了一些@ConfigMapping错误。但是这个测试没有显示这个错误,但是只有在它之前运行的其他@ConfigMapping测试中,这个测试没有被标记为错误,只是被忽略为没有跳过,没有执行,没有成功,也没有失败。

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

谷歌的"Maven忽略我的QuarkusTest“带我去了这个related question,它提到了降低related question插件的等级,所以我打开-X maven调试选项,并在日志中搜索related question。我注意到,在target/surefire-reports中保存了一些报告,打开这些报告将我引向这一行:

代码语言:javascript
复制
<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启动的所有引导错误,此测试通过。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73581231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档