测试数据直接写在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. .NET去掉HTML标记

    using System.Text.RegularExpressions; /// <summary> /// 去除HTML标记 /// </summary> /// < ...

  2. jQuery点击图片弹出放大可拖动图片查看

    CSS代码: .popup-bigic { position: absolute; ; ; background: #eee; overflow: hidden; ; } .popup-bigic . ...

  3. 深入了解iPad上的MouseEvent【转】

    iPad上没有鼠标,所以手指在触发触摸事件(TouchEvent)的时候,系统也会产生出模拟的鼠标事件(MouseEvent).     这对于普通网页的浏览需求而言,基本可以做到与PC端浏览器无明显 ...

  4. c#.net 调用BouncyCastle生成PEM格式的私钥和公钥

    RsaKeyPairGenerator r = new RsaKeyPairGenerator(); r.Init()); AsymmetricCipherKeyPair keys = r.Gener ...

  5. HackerRank "Playing with numbers"

    This is 'Difficult' - I worked out it within 45mins, and unlocked HackerRank Algorithm Level 80 yeah ...

  6. .net下连接数据库

    可以新建一个按钮,在click事件下,写入一下代码 using( SqlConnection conn=new SqlConnection(Data source=.; Catalog Initial ...

  7. (C/C++) 算法,编程题

    注: 如下的题目皆来自互联网,答案是结合了自己的习惯稍作了修改. 1. 求一个数的二进制中的1的个数. int func(int x) { ; while (x) { count++; x = x&a ...

  8. Asp.net MVC 中Controller返回值类型ActionResult

    [Asp.net MVC中Controller返回值类型] 在mvc中所有的controller类都必须使用"Controller"后缀来命名并且对Action也有一定的要求: 必 ...

  9. android listView Exception

    - ::-/com.tongyan.tutelage W/System.err﹕ java.text.ParseException: Unparseable date: ) - ::-/com.ton ...

  10. c++,opencv播放视频

    #include <opencv2\opencv.hpp>#include <iostream> using namespace cv;using namespace std; ...