草庐IT

test-environments

全部标签

java - 为什么我无法在使用 Maven 的 Junit 测试运行中访问 src/test/resources?

我在运行以下代码时遇到问题:configService.setMainConfig("src/test/resources/MainConfig.xml");从Junit@Before方法中。这是Maven构建其目标文件夹的方式吗? 最佳答案 直接访问MainConfig.xml。src/test/resources目录内容放置在您的CLASSPATH的根目录中。更准确地说:src/test/resources的内容被复制到target/test-classes中,所以如果你有以下项目结构:.└──src└──test├──java

java - 命名约定 JUnit 后缀或前缀 Test

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题吗?更新问题,以便editingthispost提供事实和引用来回答它.关闭5年前。Improvethisquestion待测类MyClass.javaJUnit测试用例名称替代:TestMyClass.javaMyClassTest.javahttp://moreunit.sourceforge.net似乎使用“测试”作为前缀默认值,但我已经看到了这两种用途。在eclipse中将整个项目作为单元测试运行时,两者似乎都被识别,因为它是为@Test解析的类内部的注释。我猜maven做同样的事情。哪个是首选?

java.lang.ClassCastException : java. util.LinkedHashMap 无法转换为 com.testing.models.Account

我遇到以下错误:java.lang.ClassCastException:java.util.LinkedHashMapcannotbecasttocom.testing.models.Account下面的代码finalintexpectedId=1;TestnewTest=create();intexpectedResponseCode=Response.SC_OK;ArrayListaccount=given().when().expect().statusCode(expectedResponseCode).get("accounts/"+newTest.id()+"/users

java - Spring 3.1配置: environment not injected

我在spring3.1配置中使用以下内容:@Configuration@EnableTransactionManagementpublicclassDataConfig{@InjectprivateEnvironmentenv;@InjectprivateDataSourcedataSource;//@BeanpublicSpringLiquibaseliquibase(){SpringLiquibaseb=newSpringLiquibase();b.setDataSource(dataSource);b.setChangeLog("classpath:META-INF/db-cha

java - 使用 JUnit 5 的 spring-boot-starter-test

从2.0.6开始使用spring-boot-starter-test会引入JUnit4依赖项。如何使用spring-boot-starter-test(通过Gradle),但使用JUnit5,而不引入JUnit4依赖项?如果有帮助,这里是Gradle的依赖输出的一部分:+---org.springframework.boot:spring-boot-starter-test->2.0.5.RELEASE|+---org.springframework.boot:spring-boot-starter:2.0.5.RELEASE(*)|+---org.springframework.bo

java - spring 4 - 找到接口(interface) org.springframework.test.context.TestContext,但是应该有类

在Spring核心从3.2迁移到4后,我开始收到“Foundinterfaceorg.springframework.test.context.TestContext,butclassisexpected”异常。我正在使用mvncleantest和java7作为maven编译器版本。有什么想法吗? 最佳答案 固定。Spring测试数据库单元库有问题。这里有一些问题的描述https://github.com/springtestdbunit/spring-test-dbunit/issues/46-mavenrepos1.0.1中可见

java - 使用 junit test 将命令行参数传递给 Spring Boot 应用程序

我有一个非常基本的SpringBoot应用程序,它需要来自命令行的参数,没有它就无法工作。这是代码。@SpringBootApplicationpublicclassApplicationimplementsCommandLineRunner{privatestaticfinalLoggerlog=LoggerFactory.getLogger(Application.class);@AutowiredprivateReaderreader;@AutowiredprivateWriterwriter;publicstaticvoidmain(String[]args){SpringAp

spring - @Value 注解和 Environment API 的区别?

使用@Value注解注入(inject)类的字段和使用SpringEnvironmentAPI查找它们之间是否存在显着差异?一个比另一个更可取(以及在什么情况下)?使用@Value的示例:classConfig{@Value("${db.driverClassName}")privateStringdriverClassName;@Value("${db.url}")privateStringurl;@Value("${db.username}")privateStringusername;@Value("${db.password}")privateStringpassword;@B

java - 有没有像 : #{systemProperties ['environment_variable_name' ]} to get the system variable? 这样的语法

在Spring的applicationcontext.xml文件中使用#{systemProperties['environment']}是否返回与环境关联的值?或者有什么办法可以在springapplicationcontext.xml文件中获取系统变量值。 最佳答案 当我没记错的时候,有区别:您可以通过不同的方式访问系统属性:#{systemProperties['databaseName']}#{systemProperties.databaseName}${databaseName}//$而不是#!!与#{systemPro

java - 在xml中定义Spring @PropertySource 并在Environment中使用

在springJavaConfig中,我可以定义属性源并注入(inject)到环境中@PropertySource("classpath:application.properties")@InjectprivateEnvironmentenvironment;如果在xml中,我该怎么做?我正在使用context:property-placeholder,并在JavaConfig类@ImportResource上导入xml。但我无法使用environment.getProperty("xx")检索属性文件中定义的属性 最佳答案 AFA