JUnit4 和 Guice 测试库 Acai

码农软件 · 软件分类 · 测试工具 · 2019-11-22 16:13:45

软件介绍

Acai 是 JUnit4Guice 的测试库,可以更容易的编写应用功能测试。

主要特性:

  • 注入测试需要的助手类

  • 启动测试需要的任意的服务

  • 运行测试之间的服务清理

  • 按照正确顺序启动多个服务

  • 创建测试作用域绑定

Acai 主要针对的是应用大型功能测试。

安装

<dependency>
  <groupId>com.google.acai</groupId>
  <artifactId>acai</artifactId>
  <version>0.1</version>
  <scope>test</scope>
</dependency>

使用 Acai 进行测试注入

@RunWith(JUnit4.class)
public class SimpleTest {
  @Rule public Acai acai = new Acai(MyTestModule.class);
  @Inject private MyClass foo;
  @Test
  public void checkSomethingWorks() {
    // Use the injected value of foo here
  }
  private static class MyTestModule extends AbstractModule {
    @Override protected void configure() {
      bind(MyClass.class).to(MyClassImpl.class);
    }
  }
}

使用 Acai 启动服务

@RunWith(JUnit4.class)
public class ExampleFunctionalTest {
  @Rule public Acai acai = new Acai(MyTestModule.class);
  @Inject private MyServerClient serverClient;
  @Test
  public void checkSomethingWorks() {
    // Call the running server and test some behaviour here.
    // Any state will be cleared by MyFakeDatabaseWiper after each
    // test case.
  }
  private static class MyTestModule extends AbstractModule {
    @Override protected void configure() {
      // Normal Guice modules which configure your
      // server with in-memory versions of backends.
      install(MyServerModule());
      install(MyFakeDatabaseModule());
      install(new TestingServiceModule() {
        @Override protected void configureTestingServices() {
          bindTestingService(MyServerRunner.class);
          bindTestingService(MyFakeDatabaseWiper.class);
        }
      });
    }
  }
  private static class MyServerRunner implements TestingService {
    @Inject private MyServer myServer;
    @BeforeSuite void startServer() {
      myServer.start().awaitStarted();
    }
  }
  private static class MyFakeDatabaseWiper implements TestingService {
    @Inject private MyFakeDatabse myFakeDatabase;
    @AfterTest void wipeDatabase() {
      myFakeDatabase.wipe();
    }
  }
}

本文地址:https://codercto.com/soft/d/19557.html

美团机器学习实践

美团机器学习实践

美团算法团队 / 人民邮电出版社 / 2018-8-1 / 79.00元

人工智能技术正以一种超快的速度深刻地改变着我们的生活,引导了第四次工业革命。美团作为国内O2O领域领 先的服务平台,结合自身的业务场景和数据,积极进行了人工智能领域的应用探索。在美团的搜索、推荐、计算广告、风控、图像处理等领域,相关的人工智能技术得到广泛的应用。本书包括通用流程、数据挖掘、搜索和推荐、计算广告、深度学习以及算法工程6大部分内容,全面介绍了美团在多个重要方面对机器学习的应用。 ......一起来看看 《美团机器学习实践》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具