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

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

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

 package com.testdata;

 import org.springframework.boot.context.properties.ConfigurationProperties;

 /**
* Created by sallyzhang on 4/26/16.
*/ @ConfigurationProperties(prefix="home", locations = "classpath:homeTestData.properties")
public class HomeTestDataSettings { private String homeValue;
private String contentValue;
private String age;
private String builtYear;
private String constructionType;
private String roofType;
private String suburbStatePostcode;
private String address;
private String homeExcess;
private String contentExcess;
private String sourceOfBusiness;
private String username;
private String password; public String getHomeValue() {
return homeValue;
} public void setHomeValue(String homeValue) {
this.homeValue = homeValue;
} public String getContentValue() {
return contentValue;
} public void setContentValue(String contentValue) {
this.contentValue = contentValue;
} public String getAge() {
return age;
} public void setAge(String age) {
this.age = age;
} public String getBuiltYear() {
return builtYear;
} public void setBuiltYear(String builtYear) {
this.builtYear = builtYear;
} public String getConstructionType() {
return constructionType;
} public void setConstructionType(String constructionType) {
this.constructionType = constructionType;
} public String getRoofType() {
return roofType;
} public void setRoofType(String roofType) {
this.roofType = roofType;
} public String getSuburbStatePostcode() {
return suburbStatePostcode;
} public void setSuburbStatePostcode(String suburbStatePostcode) {
this.suburbStatePostcode = suburbStatePostcode;
} public String getAddress() {
return address;
} public void setAddress(String address) {
this.address = address;
} public String getHomeExcess() {
return homeExcess;
} public void setHomeExcess(String homeExcess) {
this.homeExcess = homeExcess;
} public String getContentExcess() {
return contentExcess;
} public void setContentExcess(String contentExcess) {
this.contentExcess = contentExcess;
} public String getSourceOfBusiness() {
return sourceOfBusiness;
} public void setSourceOfBusiness(String sourceOfBusiness) {
this.sourceOfBusiness = sourceOfBusiness;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
}
}

HomeTestDataSettings

然后在入口类PropertyTestDataDemo加上EnableConfigurationProperties

 @SpringBootApplication
@EnableConfigurationProperties({HomeTestDataSettings.class,MotorTestDataSettings.class})
public class PropertyTestDataDemo { public static void main(String[] args) {
SpringApplication.run(PropertyTestDataDemo.class, args);
}
}

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. [Hibernate] - Study test project

    最近玩Hibernate的测试代码工程: http://files.cnblogs.com/HD/TestHibernate.7z

  2. SPOJ #5 The Next Palindrome

    "not more than 1000000 digits" means an efficient in-place solution is needed. My first so ...

  3. sgu233 little kings

    题目大意: 有n*n的棋盘上放k个国王.国王可以攻击与它相邻的八个格子.现在要使国王不相互攻击,有多少种放置的方案数.一个格子不能放两个国王. n<=10,k<=n*n. 分析:简单的状态 ...

  4. iwpriv

    AuthMode             {OPEN,SHARED,WEPAUTO,WPAPSK,WPA2PSK,WPANONE} ::Set Authentication Mode EncrypTy ...

  5. 黄聪:get_posts 函数 | wordpress

    get_posts 函数,简单的来讲是 get_post 的复数新形势,但因为是文章多篇提取,所以使用方法上却略有不同,支持众多参数选择需要提取的文章,在 CMS 主题中经常被用到,当然如果你对 Wo ...

  6. 内存修改mfc

    vc++6.0,内涵图

  7. PLSQL_闪回操作6_Flashback Database

    2014-12-09 Created By BaoXinjian

  8. 转载__UI之Frgment

    http://www.cnblogs.com/plokmju/p/3239265.html 前言 开门见山开篇名义,本篇博客将讲解一下Android中Fragment的内容,必要的地方会提供相应的演示 ...

  9. VI下删除所有内容

    让光标在一个位置 , 如果全删就放在问价开始的位置 , 在非编辑的状态下输入dG(注意大小写) , 这样光标之后的所有行都会被删掉

  10. Python进阶03 模块

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 我们之前看到了函数和对象.从本质上来说,它们都是为了更好的组织已经有的程序,以方便 ...