弹簧靴仅用于单元测试

时间:2018-02-08 14:31:50

标签: unit-testing spring-boot

我有一个使用经典弹簧配置和xml的应用程序,可以使用弹簧启动仅用于单元测试吗?

像这样:

for

1 个答案:

答案 0 :(得分:0)

好的,只需使用spring boot main方法创建一个类:

        @SpringBootApplication
        @ImportResource(locations = { "classpath:security-context.xml", "classpath:persistence-context-test.xml", "classpath:core-context.xml", "classpath:web-context.xml" })
        public class SimpleBootCxfSystemTestApplication {

            /**
             * The main method.
             *
             * @param args
             *            the arguments
             */
            public static void main(String[] args) {
                SpringApplication.run(SimpleBootCxfSystemTestApplication.class, args);
            }
        }

并改变类测试:

    @RunWith(SpringJUnit4ClassRunner.class)
    @SpringApplicationConfiguration(classes = SimpleBootCxfSystemTestApplication.class)
    @WebIntegrationTest("server.port:8080")
    @ActiveProfiles("test")
    @WithUserDetails(value = "testUser", userDetailsServiceBeanName = "utilisateurService")
    public class SampleTomcatApplicationTests {

    //autowired
    ...
    //test
    }