草庐IT

unit-testing - Java 项目 : Failed to load ApplicationContext

我有一个Java项目,我正在其中编写一个简单的JUNIT测试用例。我已将appplicatinoContext.xml文件复制到根java源目录中。我已经尝试过使用我在StackOverflow上读到的一些推荐设置,但仍然出现相同的错误。发生此错误是因为我的项目是java项目而不是web项目,还是这有关系?我不确定我哪里出错了。importorg.junit.Test;importorg.junit.runner.RunWith;importorg.springframework.beans.factory.annotation.Autowired;importorg.springfr

unit-testing - Java 项目 : Failed to load ApplicationContext

我有一个Java项目,我正在其中编写一个简单的JUNIT测试用例。我已将appplicatinoContext.xml文件复制到根java源目录中。我已经尝试过使用我在StackOverflow上读到的一些推荐设置,但仍然出现相同的错误。发生此错误是因为我的项目是java项目而不是web项目,还是这有关系?我不确定我哪里出错了。importorg.junit.Test;importorg.junit.runner.RunWith;importorg.springframework.beans.factory.annotation.Autowired;importorg.springfr

java - 每次测试后重新加载 Spring 应用程序上下文

我有一个包含2个测试的测试类:@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations={"classpath:applicationContextTest.xml"})@Transactional@TransactionConfiguration(defaultRollback=true)publicclassMyITestextendsimplementsBeanFactoryAware{privateBeanFactorybeanFactory;@Testpublicvoidtest1()thro

java - 每次测试后重新加载 Spring 应用程序上下文

我有一个包含2个测试的测试类:@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations={"classpath:applicationContextTest.xml"})@Transactional@TransactionConfiguration(defaultRollback=true)publicclassMyITestextendsimplementsBeanFactoryAware{privateBeanFactorybeanFactory;@Testpublicvoidtest1()thro

java - 如何在 Junit 中使用 @InjectMocks 和 @Autowired 注释

我有一个A类,它使用3个不同的Autowiring类publicclassA(){@AutowiredprivateBb;@AutowiredprivateCc;@AutowiredprivateDd;}在测试它们时,我希望只有2个类(B和C)作为模拟,并让D类正常运行时Autowiring,此代码不适用于我:@RunWith(MockitoJUnitRunner.class)publicclassaTest(){@InjectMocksprivateAa;@MockprivateBb;@MockprivateCc;@AutowiredprivateDd;}真的有可能吗?

java - 如何在 Junit 中使用 @InjectMocks 和 @Autowired 注释

我有一个A类,它使用3个不同的Autowiring类publicclassA(){@AutowiredprivateBb;@AutowiredprivateCc;@AutowiredprivateDd;}在测试它们时,我希望只有2个类(B和C)作为模拟,并让D类正常运行时Autowiring,此代码不适用于我:@RunWith(MockitoJUnitRunner.class)publicclassaTest(){@InjectMocksprivateAa;@MockprivateBb;@MockprivateCc;@AutowiredprivateDd;}真的有可能吗?

java - 在 JUnit 中使用 Spring 测试服务时如何回滚数据库事务?

我测试我的DAO和服务没有问题,但是当我测试INSERTs或UPDATEs时,我想回滚事务并且不影响我的数据库。我在我的服务中使用@Transactional来管理事务。我想知道,是否有可能知道一个事务是否可以,但回滚它以防止更改数据库?这是我的测试:@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations="classpath:/META-INF/spring.cfg.xml")@TransactionConfiguration(defaultRollback=true)publicclassMySe

java - 在 JUnit 中使用 Spring 测试服务时如何回滚数据库事务?

我测试我的DAO和服务没有问题,但是当我测试INSERTs或UPDATEs时,我想回滚事务并且不影响我的数据库。我在我的服务中使用@Transactional来管理事务。我想知道,是否有可能知道一个事务是否可以,但回滚它以防止更改数据库?这是我的测试:@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations="classpath:/META-INF/spring.cfg.xml")@TransactionConfiguration(defaultRollback=true)publicclassMySe

java - Spring 配置文件和测试

我有一个Web应用程序,其中存在一个典型问题,即它需要针对不同环境使用不同的配置文件。一些配置作为JNDI数据源放置在应用服务器中,但是一些配置保留在属性文件中。因此我想使用Spring配置文件功能。我的问题是我没有让测试用例运行。context.xml:测试:@RunWith(SpringJUnit4ClassRunner.class)@TestExecutionListeners({TestPreperationExecutionListener.class})@Transactional@ActiveProfiles(profiles="localtest")@ContextCo

java - Spring 配置文件和测试

我有一个Web应用程序,其中存在一个典型问题,即它需要针对不同环境使用不同的配置文件。一些配置作为JNDI数据源放置在应用服务器中,但是一些配置保留在属性文件中。因此我想使用Spring配置文件功能。我的问题是我没有让测试用例运行。context.xml:测试:@RunWith(SpringJUnit4ClassRunner.class)@TestExecutionListeners({TestPreperationExecutionListener.class})@Transactional@ActiveProfiles(profiles="localtest")@ContextCo