简体   繁体   English

如何为在运行时加载函数的应用程序编写测试?

[英]How do I write tests for an application that loads functions at run time?

I built a backend server ( ready-to-serve ) that can load jar files as plugins and use the methods in it to serve different functionalities.我构建了一个后端服务器(随时可用),它可以将jar文件作为插件加载并使用其中的方法来提供不同的功能。

I want to write tests for it but I'm not sure what kind of tests I should write.我想为它编写测试,但我不确定我应该编写什么样的测试。

You should have a look at the different kinds of tests.你应该看看不同类型的测试。 Unit tests, integration tests, end-to-end tests.单元测试、集成测试、端到端测试。

In case you are writing the code for the imported jars yourself, you could write unit tests for the helper functions and services inside.如果您自己为导入的 jar 编写代码,您可以为里面的辅助函数和服务编写单元测试。 They should be small and pure (self contained).它们应该小而纯(自包含)。

I guess, that you have a generalised interface exposed with each jar, that your main application reuses to communicate with the jar.我猜,你有一个与每个 jar 公开的通用接口,你的主应用程序重用它与 j​​ar 进行通信。

You could write a general integration test, that imports one of the jars and calls a general method, to show, that the execution succeeded.您可以编写一个通用集成测试,导入其中一个 jar 并调用通用方法,以显示执行成功。 Something like a health check.类似于健康检查。 Then you could write more tests for other functions and the expected results, though they will probably become more focused on each separate jar.然后您可以为其他功能和预期结果编写更多测试,尽管它们可能会更加专注于每个单独的 jar。

When it comes to testing plugins having only Unit tests is not enough.在测试插件时,只有单元测试是不够的。 You'll need integration tests too, otherwise not possible to test combinations of plugins and/or dependencies between them.您也需要集成测试,否则无法测试插件和/或它们之间的依赖关系的组合。

Backing to your github project: from what i see, you basically need to test only plugin API and maybe some shared resources: configuration file, datasources and so on.回到你的 github 项目:据我所知,你基本上只需要测试插件 API 和一些共享资源:配置文件、数据源等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM