Jboot v3.9.15 发布,带来了强大的单元测试能力

栏目: 软件资讯 · 发布时间: 4年前

内容简介:Jboot 一个更简单的分布式、微服务框架。 Jboot是一个基于 JFinal、JFinal-Undertow、Dubbo、Seata、Sentinel、ShardingSphere、Nacos 等开发的微服务框架,帮助开发者降低微服务、分布式开发门槛。爽爽开发,快乐...

Jboot 一个更简单的分布式、微服务框架。

Jboot是一个基于 JFinal、JFinal-Undertow、Dubbo、Seata、Sentinel、ShardingSphere、Nacos 等开发的微服务框架,帮助开发者降低微服务、分布式开发门槛。爽爽开发,快乐生活。

到目前为止,Jboot 已经开源超过了 5 年的时间,迭代了 190+ 个版本,已经被超过 1000+ 公司在使用,其中包含了多个知名的上市公司。

Jboot v3.9.15  主要是针对 Junit4 和 junit5 带来了强大的单元测试能力。

在 junit4 如下代码所示:

@RunWith(JbootRunner.class)
public class MyAppTester {

    private static MockMvc mvc = new MockMvc();

    @Inject
    private MyService myService;

    @Test
    public void test_url_aaa() {
        MockMvcResult mvcResult = mvc.get("/aaa");

        mvcResult.printResult()
                .assertThat(result -> Assert.assertNotNull(result.getContent()))
                .assertTrue(result -> result.getHttpCode() == 200);
    }

    @Test
    public void test_url_bbb() {
        MockMvcResult mvcResult = mvc.get("/bbb");

        mvcResult.printResult()
                .assertThat(result -> Assert.assertNotNull(result.getContent()))
                .assertTrue(result -> result.getHttpCode() == 200);
    }

    @Test
    public void test_my_service() {
        Ret ret = myService.doSomeThing();
        Assert.assertNotNull(ret);
        //.....
    }
}

我们可以通过 MockMvc 可以对 JFinal(Jboot) 中的 Controller、Interceptor、Handler 等进行测试,无需启动 JFinal 服务。

同时可以直接通过 @Inject 或者 @RPCInject 把 Service 注入到 MyAppTester 里,直接对 service 进行测试。

在 junit5 中,代码如下:

@ExtendWith(JbootExtension.class)
public class MyAppTester {

    private static MockMvc mvc = new MockMvc();

    @Inject
    private MyService myService;

    @Test
    public void test_url_aaa() {
        MockMvcResult mvcResult = mvc.get("/aaa");

        mvcResult.printResult()
                .assertThat(result -> Assertions.assertNotNull(result.getContent()))
                .assertTrue(result -> result.getHttpCode() == 200);
    }

    @Test
    public void test_url_bbb() {
        MockMvcResult mvcResult = mvc.get("/bbb");

        mvcResult.printResult()
                .assertThat(result -> Assertions.assertNotNull(result.getContent()))
                .assertTrue(result -> result.getHttpCode() == 200);
    }

    @Test
    public void test_my_service() {
        Ret ret = myService.doSomeThing();
        Assertions.assertNotNull(ret);
        //.....
    }
}

主要的不同点是 MyApTester 类的配置不同而已。Junit4 使用 @RunWith(JbootRunner.class) 配置,而 Junit5 使用 @ExtendWith(JbootExtension.class) 配置。

 

Jboot v3.9.15 更新内容如下:

  • 新增:新增单元测试的辅助类的支持
  • 新增:ActionReporter 新增 render 信息的输出功能
  • 新增:工具类 ReflectUtil.java
  • 新增:为 undertow 新增默认的 content-type,解决 mp4 等视频不能播放的问题
  • 新增:ValidErrorRender,方便用户自定义 "数据验证" 错误的渲染器
  • 新增:新增配置 "jboot.app.listener",用于配置可以执行的 appListener
  • 新增:新增配置 "jboot.json.skipModelAttrs" 和 "jboot.json.skipBeanGetters" 配置
  • 新增:devModel 可以动态配置,方便在某些场景下切换 devMode
  • 优化:调整默认的JbootShiroInvokeListener实现,保存被拦截的请求便于后续跳转使用,感谢 @没牙的小朋友
  • 优化:JbootGatewayHandler 默认添加在系统里,方便进行动态路由
  • 优化:JbootGatewayHealthChecker 的代码
  • 优化:升级 JFinal 等依赖到最新版本
  • 优化:对 ClickHouse 高级版本 驱动 进行适配
  • 修复:jboot.properties配置文件中 jboot.shiro.ini 配置未生效的问题,感谢 @没牙的小朋友
  • 修复:在某些情况下 PathKit.getWebRootPath 得到错误结果的问题
  • 修复:当 Interceptor 被 cglib 代理时,无法正确输出其日志的问题
  • 修复:在某些极端场景下,PathKit.getWebRootPath() 可能出错的问题
  • 修复:当查询的 Page 为 null 时,分页的总页数数据错误的问题

Jboot 开发文档:

https://jbootprojects.gitee.io/docs/

同时,Jboot 官方也推出了收费的、企业级快速开发框架 JbootAdmin (如下图所示),关于 JbootAdmin 的功能详情或者演示,请咨询海哥。

Jboot v3.9.15 发布,带来了强大的单元测试能力

maven 依赖:

<dependency>
    <groupId>io.jboot</groupId>
    <artifactId>jboot</artifactId>
    <version>3.9.15</version>
</dependency>

Hello World:

@RequestMapping("/")
public class HelloWorld extends JbootController {

    public void index(){
        renderText("hello world");
    }

    public static void main(String[] args){
        JbootApplication.run(args);
    }
}

以上所述就是小编给大家介绍的《Jboot v3.9.15 发布,带来了强大的单元测试能力》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Java Concurrency in Practice

Java Concurrency in Practice

Brian Goetz、Tim Peierls、Joshua Bloch、Joseph Bowbeer、David Holmes、Doug Lea / Addison-Wesley Professional / 2006-5-19 / USD 59.99

This book covers: Basic concepts of concurrency and thread safety Techniques for building and composing thread-safe classes Using the concurrency building blocks in java.util.concurrent Pe......一起来看看 《Java Concurrency in Practice》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具