<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          AcaiJUnit4 和 Guice 測試庫

          聯(lián)合創(chuàng)作 · 2023-10-01 17:50

          Acai 是 JUnit4Guice 的測試庫,可以更容易的編寫應(yīng)用功能測試。

          主要特性:

          • 注入測試需要的助手類

          • 啟動測試需要的任意的服務(wù)

          • 運(yùn)行測試之間的服務(wù)清理

          • 按照正確順序啟動多個服務(wù)

          • 創(chuàng)建測試作用域綁定

          Acai 主要針對的是應(yīng)用大型功能測試。

          安裝

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

          使用 Acai 進(jìn)行測試注入

          @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 啟動服務(wù)

          @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();
              }
            }
          }
          瀏覽 17
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  午夜婷婷网 | 国产一级内射 | 日韩女同性爱一区二区三区四区精品 | 国产女人18毛片水18精品 | 色老扳AV |