【问题标题】:Spring Test. Get access of test class of dependent project?春季测试。获取依赖项目的测试类的访问权限?
【发布时间】:2015-11-26 05:50:22
【问题描述】:

我有多模块项目;我正在为测试目的创建 Junit 测试类。

但问题是,当我运行我的核心项目测试时,只使用 2 个包 ComponentScan 进行测试。它无法找到 Util Project Test 配置。(构建 JAR 时排除测试包)

因此,我得到 No qualifying bean of type 异常,因为 Util 项目中缺少 Configuration 类。

@SpringBootApplication
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { CreateProfileTest.class })
@ComponentScan({"com.myproject.testconfig","com.myproject.module"})
@EnableAutoConfiguration
public class CreateProfileTest {


    @Test
    public void myMethod()
    {

    }
}

那么,我如何在 Core Project Test 中访问 Util Project Test Config。

Job -> Core -> Util(这里Core依赖Util)

现在

 CoreProject/
             src/main/com.myproject.config
             src/main/com.myproject.module
             src/test/com.myproject.testconfig 

 UtilPorject/
             src/main/com.myproject.config
             src/main/com.myproject.module
             src/test/com.myproject.testconfig 

如果有任何替代方法可以实现这一点,或者我在这里做错了什么,请告诉我。

我正在使用 Maven 和 Spring Boot。

【问题讨论】:

    标签: java spring maven junit spring-boot


    【解决方案1】:

    在我看来,这是类路径的问题。您是否尝试在 CoreProject pom.xml 中添加它?

        <dependency>
            <groupId>...</groupId>
            <artifactId>util-project</artifactId>
            <version>...</version>
            <classifier>tests</classifier>
            <scope>test</scope>
        </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-13
      • 1970-01-01
      • 2011-09-26
      • 2012-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-01
      相关资源
      最近更新 更多