JUnit4和Guice测试库Acai.zip

时间:2022-08-08 01:51:11
【文件属性】:
文件名称:JUnit4和Guice测试库Acai.zip
文件大小:42KB
文件格式:ZIP
更新时间:2022-08-08 01:51:11
开源项目 Acai 是 JUnit4 和 Guice 的测试库,可以更容易的编写应用功能测试。主要特性:注入测试需要的助手类启动测试需要的任意的服务 运行测试之间的服务清理按照正确顺序启动多个服务 创建测试作用域绑定Acai 主要针对的是应用大型功能测试。安装   com.google.acai   acai   0.1   test 使用 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();     }   } } 标签:Acai
【文件预览】:
acai-master
----.gitignore(225B)
----README.md(11KB)
----pom.xml(8KB)
----LICENSE(11KB)
----CONTRIBUTING.md(3KB)
----src()
--------test()
--------main()
----version-rules.xml(1KB)
----.travis.yml(143B)

网友评论