我有一個基於spring的Java EE web應用程序。我正在測試使用junit的數據訪問對象(DAO)的「存儲庫」。我使用maven來構建和測試我的項目。一個單元測試我的一個例子如下所示:如何防止在單元測試期間反覆加載彈簧應用程序上下文
@ContextConfiguration(locations = {"classpath:spring/business-objects.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class JpaUserRepositoryTests {
@AutoWired
UserRepository userRepository;
@Test
@Transactional
public void testCreate() {
boolean result = userRepository.create(new User("name","pass"));
Assert.assertTrue(result);
}
}
我的行家-萬無一失-插件配置如下所示。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
</configuration>
</plugin>
我的問題是,我有多個庫測試,每次我跑「MVN清潔測試」的時候,每個倉庫測試類,Spring應用程序上下文加載一遍又一遍。有沒有什麼辦法來配置我的測試,以便Spring應用程序上下文只爲我的所有存儲庫測試加載一次?
謝謝,我認爲就是這樣。我只是從2.13更新到2.15。 –