简体   繁体   中英

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.

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. 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.

You could write a general integration test, that imports one of the jars and calls a general method, to show, that the execution succeeded. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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