测试数据直接写在Property文件中,如下图:

application.properties是系统自动生成,我添加了两个Property文件:HomeTestData.properties和motorTestData.properties来存储不同的测试数据。数据只要遵循Key=value格式即可,就像下面这样:

接下来为添加的两个Property文件中的数据生成get和set方法:

  1. package com.testdata;
  2.  
  3. import org.springframework.boot.context.properties.ConfigurationProperties;
  4.  
  5. /**
  6. * Created by sallyzhang on 4/26/16.
  7. */
  8.  
  9. @ConfigurationProperties(prefix="home", locations = "classpath:homeTestData.properties")
  10. public class HomeTestDataSettings {
  11.  
  12. private String homeValue;
  13. private String contentValue;
  14. private String age;
  15. private String builtYear;
  16. private String constructionType;
  17. private String roofType;
  18. private String suburbStatePostcode;
  19. private String address;
  20. private String homeExcess;
  21. private String contentExcess;
  22. private String sourceOfBusiness;
  23. private String username;
  24. private String password;
  25.  
  26. public String getHomeValue() {
  27. return homeValue;
  28. }
  29.  
  30. public void setHomeValue(String homeValue) {
  31. this.homeValue = homeValue;
  32. }
  33.  
  34. public String getContentValue() {
  35. return contentValue;
  36. }
  37.  
  38. public void setContentValue(String contentValue) {
  39. this.contentValue = contentValue;
  40. }
  41.  
  42. public String getAge() {
  43. return age;
  44. }
  45.  
  46. public void setAge(String age) {
  47. this.age = age;
  48. }
  49.  
  50. public String getBuiltYear() {
  51. return builtYear;
  52. }
  53.  
  54. public void setBuiltYear(String builtYear) {
  55. this.builtYear = builtYear;
  56. }
  57.  
  58. public String getConstructionType() {
  59. return constructionType;
  60. }
  61.  
  62. public void setConstructionType(String constructionType) {
  63. this.constructionType = constructionType;
  64. }
  65.  
  66. public String getRoofType() {
  67. return roofType;
  68. }
  69.  
  70. public void setRoofType(String roofType) {
  71. this.roofType = roofType;
  72. }
  73.  
  74. public String getSuburbStatePostcode() {
  75. return suburbStatePostcode;
  76. }
  77.  
  78. public void setSuburbStatePostcode(String suburbStatePostcode) {
  79. this.suburbStatePostcode = suburbStatePostcode;
  80. }
  81.  
  82. public String getAddress() {
  83. return address;
  84. }
  85.  
  86. public void setAddress(String address) {
  87. this.address = address;
  88. }
  89.  
  90. public String getHomeExcess() {
  91. return homeExcess;
  92. }
  93.  
  94. public void setHomeExcess(String homeExcess) {
  95. this.homeExcess = homeExcess;
  96. }
  97.  
  98. public String getContentExcess() {
  99. return contentExcess;
  100. }
  101.  
  102. public void setContentExcess(String contentExcess) {
  103. this.contentExcess = contentExcess;
  104. }
  105.  
  106. public String getSourceOfBusiness() {
  107. return sourceOfBusiness;
  108. }
  109.  
  110. public void setSourceOfBusiness(String sourceOfBusiness) {
  111. this.sourceOfBusiness = sourceOfBusiness;
  112. }
  113.  
  114. public String getUsername() {
  115. return username;
  116. }
  117.  
  118. public void setUsername(String username) {
  119. this.username = username;
  120. }
  121.  
  122. public String getPassword() {
  123. return password;
  124. }
  125.  
  126. public void setPassword(String password) {
  127. this.password = password;
  128. }
  129. }

HomeTestDataSettings

然后在入口类PropertyTestDataDemo加上EnableConfigurationProperties

  1. @SpringBootApplication
  2. @EnableConfigurationProperties({HomeTestDataSettings.class,MotorTestDataSettings.class})
  3. public class PropertyTestDataDemo {
  4.  
  5. public static void main(String[] args) {
  6. SpringApplication.run(PropertyTestDataDemo.class, args);
  7. }
  8. }

PropertyTestDataDemo

这里解释下,PropertyTestDataDemo是SpringBoot的入口类,里面的mian函数就是入口,如果实在不明白,就记住:不要删了,就可以了。

如需转载,请注明出处,这是对他人劳动成果的尊重~

使用Spring的Property文件存储测试数据 - 添加测试数据的更多相关文章

  1. 使用Spring的Property文件存储测试数据 - 初始化

    本系列博客有一个前提:只使用Junit编写测试,不使用类似Cucumber这类BDD框架. 用Cucumber的时候,测试数据可以直接写在feature文件里,但是仅仅使用Junit(不要问我为什么只 ...

  2. 使用Spring的Property文件存储测试数据 - 编写测试和调用测试数据

    准备好测试数据后,我们可以开始编写测试了,在测试用例中调用我们property文件中的测试数据. 我自己写了一个TestCase作为所有测试类基类,基类中定义了两个变量来代表之前建好的两个测试数据文件 ...

  3. Spring property文件配置方法以及如何与工程分离

    1,Spring使用property文件作为配置源    工程中难免出现一些需要每次部署都需要配置的参数,如数据源连接参数等,测试环境跟实际运行环境是不一样的.    使用spring框架的话,这些参 ...

  4. spring 配置文件 引入外部的property文件的两种方法

    spring  的配置文件 引入外部的property文件的两种方法 <!-- 引入jdbc配置文件    方法一 --> <bean id="propertyConfig ...

  5. 「一站式」兼容所有云厂商文件存储Spring Boot 实现

    背景 在互联网发展的今天,近乎所有的云厂商都提供对象存储服务.一种海量.安全.低成本.高可靠的云存储服务,适合存放任意类型的文件.容量和处理能力弹性扩展,多种存储类型供选择,全面优化存储成本. 当我们 ...

  6. 如何在java web工程下建立存储property文件的文件夹,让Java程序直接读取

    如何在java web工程下建立存储property文件的文件夹,让Java程序直接读取: 步骤如下:

  7. Spring MVC的文件上传和下载

    简介: Spring MVC为文件上传提供了直接的支持,这种支持使用即插即用的MultipartResolver实现的.Spring MVC 使用Apache Commons FileUpload技术 ...

  8. Spring MVC 实现文件的上传和下载

    前些天一位江苏经贸的学弟跟我留言问了我这样一个问题:“用什么技术来实现一般网页上文件的上传和下载?是框架还是Java中的IO流”.我回复他说:“使用Spring MVC框架可以做到这一点,因为Spri ...

  9. Spring简单的文件配置

    Spring简单的文件配置 “计应134(实验班) 凌豪” 一.Spring文件配置 spring至关重要的一环就是装配,即配置文件的编写,接下来我按刚才实际过程中一步步简单讲解. 首先,要在web. ...

随机推荐

  1. Eclipse设置UTF-8

    将Eclipse所有的设置都设置为UTF-8: 1) Window -> Preferences -> General -> Workspace -> Text file en ...

  2. HackerRank "Median Updates"

    Same as LintCode "Sliding Window Median", but requires more care on details - no trailing ...

  3. HackerRank "Self Balancing Tree"

    Something to learn: Rotation ops in AVL tree does not require recursion. https://github.com/andreima ...

  4. 【Spring学习笔记-0】Spring开发所需要的核心jar包

    spring开发所需要的核心jar 1. libs目录下的核心jar包: 2. common-logging-xxx.jar 来自为知笔记(Wiz) 附件列表

  5. php定时执行脚本

    php定时执行脚本 ignore_user_abort(); // run script. in background set_time_limit(0); // run script. foreve ...

  6. (WPF) 文件和文件夹选择对话框。

    点击button,选择一个excel文件,并将文件名显示在textbox上. private void btnSelectErrorTableFile_Click(object sender, Rou ...

  7. HtmlParser + HttpClient 实现爬虫

    简易爬虫的实现 HttpClient 提供了便利的 HTTP 协议访问,使得我们可以很容易的得到某个网页的源码并保存在本地:HtmlParser 提供了如此简便灵巧的类库,可以从网页中便捷的提取出指向 ...

  8. Segment fault及LINUX core dump详解

    源自:http://andyniu.iteye.com/blog/1965571 core dump的概念: A core dump is the recorded state of the work ...

  9. SparkSQL项目中的应用

    Spark是一个通用的大规模数据快速处理引擎.可以简单理解为Spark就是一个大数据分布式处理框架.基于内存计算的Spark的计算速度要比Hadoop的MapReduce快上100倍以上,基于磁盘的计 ...

  10. Codeforces Round #358 (Div. 2)B. Alyona and Mex

    B. Alyona and Mex time limit per test 1 second memory limit per test 256 megabytes input standard in ...