Unit test ServiceLoader

后端 未结 1 1192
再見小時候
再見小時候 2021-02-06 02:18

I have a method that uses ServiceLoader to load services using resources.

public List getContextData(int Id)
{
  List li         


        
相关标签:
1条回答
  • 2021-02-06 02:33

    You need to copy the "provider-configuration file" into your test class directory.

    assuming your test class files are located at

    test/classes/
    

    you need to copy the "provider-configuration file" to

    test/classes/META-INF/services/your.package.ContextPlugin
    

    How to copy the files depend on your build tool (e.g. maven, gradle, ant, ...)

    As example for maven you should store them in the test resources folder.

    src/test/resources/META-INF/services/your.package.ContextPlugin
    
    0 讨论(0)
提交回复
热议问题