RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 882595
Accepted
Roberto
Roberto
Asked:2020-09-18 16:58:45 +0000 UTC2020-09-18 16:58:45 +0000 UTC 2020-09-18 16:58:45 +0000 UTC

如何在命令行上仅在远程机器上运行集成测试?

  • 772

使用命令在远程服务器上启动 Spring-boot 应用程序

java -jar target\myApp.jar --spring.profiles.active=dev

也就是说,不同服务器的不同配置文件。

在此应用程序之上运行集成测试的命令是什么?您是否需要每台服务器 - 在测试中也有自己的配置文件?是否需要在代码中以特殊方式标记 IT?

spring-boot
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Михаил Ребров
    2020-09-18T17:46:31Z2020-09-18T17:46:31Z

    >= 4.8 中有JUnit类别。

    注释@Category既可以放在类上,也可以放在方法上。
    注释@Category可以包含单个类别或数组。

    例子:

    @Category(Category1.class)
    public class SomeTest {
    
        @Test
        public void testMethod1() {
            ...
        }
    
        @Test
        public void testMethod2() {
            ....
        }
    }
    

    或者

    public class SomeTest {
    
        @Test
        @Category(Category2.class)
        public void testMethod1() {
            ...
        }
    
        @Test
        @Category({Category1.class, Category3.class})
        public void testMethod2() {
            ....
        }
    }
    

    您可以将类或接口指定为类别。
    因为 我们需要专门标记组,后者更常用。

    您可以Suite在Maven.

    从套件开始

    在我们的武器中使用Suite时,有@IncludeCategory类别包含和@ExcludeCategory排除的注释。

    例子:

    @RunWith(Categories.class)
    @IncludeCategory(Unit.class)
    @SuiteClasses( { Test1.class, Test2.class })
    public class UnitTestSuite {}
    

    和

    @RunWith(Categories.class)
    @ExcludeCategory(Unit.class)
    @SuiteClasses( { Test1.class, Test2.class })
    public class IntegrationTestSuite {}
    

    重要的是要理解:

    • 注释@ExcludeCategory,@IncludeCategory可以同时使用
    • 超过一个类,您只能指定一个注解@ExcludeCategory和一个注解@IncludeCategory
    • 一份摘要@ExcludeCategory或@IncludeCategory只能包含一个类别

    所有这些都使过程变得有点复杂。所有这一切的出路是类别继承。这里还值得注意的是,使用接口的好处是多重继承。

    public interface Category1 extends Category12,Category13 {}
    

    使用 Maven 运行

    Maven 是更灵活和使用的选项。

    首先我们需要maven-surefire-plugin

    配置示例:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12</version>
        <dependencies>
            <dependency>
                <groupId>org.apache.maven.surefire</groupId>
                <artifactId>surefire-junit47</artifactId>
                <version>2.12</version>
            </dependency>
        </dependencies>
        <configuration>
            <groups>com.example.cat.Category1</groups>
        </configuration>
    </plugin>
    

    Surefire-junit47 插件中的内部依赖必须存在,否则 Maven 将忽略 @Category 注释。

    • 标签用于排除类别。excludedGroups
    • 标签用于包含类别。groups
    • 该标签groups允许您包含多个类别

    例子:

    <configuration>
        <excludedGroups>com.example.cat.Category2</excludedGroups>
    </configuration>
    

    和

    <configuration>
        <groups>com.example.cat.Category1,com.example.cat.Category2</groups>
    </configuration>
    

    资料来源:

    • http://internetka.in.ua/group-junit-category/
    • https://maven.apache.org/surefire/maven-surefire-plugin/
    • 1

相关问题

  • 不通过 application.propeties 更改配置文件?

  • 尝试在 spring-boot 应用程序中从内存数据库切换到外部数据库时出错

  • 如何将授权用户重定向到springboot安全中的自定义URL?

  • 3rd 方 Spring Boot 库中的 Messages.properties 编码

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5