Running spring tests from executable jar

前端 未结 3 956
星月不相逢
星月不相逢 2020-12-31 19:32

I have some Spring tests which spin up the application context and tests some services. I am able to run these tests using Maven and through IDE. Now I have a requirement to

相关标签:
3条回答
  • 2020-12-31 20:27

    I have just forked your repository and I found the error. Spring factory must be the same than the one is used when test are thrown by maven. It is a must to delegate into Spring Ic in the same way like test context.

    See pull request for aditional information:

    https://github.com/SaiUpadhyayula/executabletests/pull/2

    0 讨论(0)
  • 2020-12-31 20:27

    I finally found the problem after debugging the test, it turns out that Spring while bootstrapping the TestContext will look for the TestExecutionListener's defined inside the META-INF/spring.factories file inside the spring-test jar.

    This spring.factories file should be ideally placed inside the META-INF folder of my executable jar. But what the assembly-plugin does is, it was not adding the right spring.factories file which contains the necessary TestExecutionListener's

    adding this file to src/main/resources/META-INF/spring.factories solved the problem

    # Default TestExecutionListeners for the Spring TestContext Framework
    #
    org.springframework.test.context.TestExecutionListener = \
        org.springframework.test.context.web.ServletTestExecutionListener,\
        org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener,\
        org.springframework.test.context.support.DependencyInjectionTestExecutionListener,\
        org.springframework.test.context.support.DirtiesContextTestExecutionListener,\
        org.springframework.test.context.transaction.TransactionalTestExecutionListener,\
        org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener
    
    # Default ContextCustomizerFactory implementations for the Spring TestContext Framework
    #
    org.springframework.test.context.ContextCustomizerFactory = \
        org.springframework.test.context.web.socket.MockServerContainerContextCustomizerFactory
    
    0 讨论(0)
  • 2020-12-31 20:28

    You need to install maven on the other machine to run the tests.

    If maven installation is not an viable option, create a jar containing the test classes and use this jar for running the tests. check the maven documentation - http://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html

    0 讨论(0)
提交回复
热议问题