zoukankan      html  css  js  c++  java
  • 使用Spring的Property文件存储测试数据 - 编写测试和调用测试数据

    准备好测试数据后,我们可以开始编写测试了,在测试用例中调用我们property文件中的测试数据。

    我自己写了一个TestCase作为所有测试类基类,基类中定义了两个变量来代表之前建好的两个测试数据文件,再使用Autowired进行注入:

     1 @Configuration
     2 @RunWith(SpringJUnit4ClassRunner.class)
     3 @SpringApplicationConfiguration(PropertyTestDataDemo.class)
     4 public class TestCase {
     5 
     6     @Autowired
     7     HomeTestDataSettings homeTestData;
     8 
     9     @Autowired
    10     MotorTestDataSettings motorTestData;
    11 
    12 }

    最后,新建测试类,并继承TestCase基类。在测试子类中,可直接调用定义好的homeTestData对象,用get方法读取到测试数据:

     1 public class Test_Home_Quote_And_Policy extends TestCase {
     2 
     3     @Test
     4     public void Test_Create_And_Save_HomeQuote() {
     5 
     6         assertThat(homeTestData.getHomeValue(), is("300000"));
     7 
     8     }
     9 
    10     @Before
    11     public void setup() {
    12 
    13     }
    14 
    15     @After
    16     public void teardown() {
    17 
    18     }
    19 }

    使用这个方法存储和读取测试数据,可以省下很多代码和维护测试数据文件规范和格式的时间,整个框架看上去结构很整洁,但是我没有试过在数据量很大的情况下,读取的速度会不会很慢。这仅仅是一个思路,怎样更好的维护测试数据,更好地参数化测试数据的思路。

    文中使用的框架和代码已经上传到github,小伙伴们若需要可自取:https://github.com/SallyZY/PropertyTestDataDemo

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

  • 相关阅读:
    Cannot initialize Cluster. Please check your configuration for mapreduce.framework.name
    docker-compose 安装solr+ikanalyzer
    centos 安装Python3
    spring+springmvc+mybatis 开发JAVA单体应用
    职责链模式例子
    ssm(spring、springmvc、mybatis)框架整合
    PAT (Advanced Level) Practise
    PAT (Advanced Level) Practise
    PAT (Advanced Level) Practise
    PAT (Advanced Level) Practise
  • 原文地址:https://www.cnblogs.com/sallyzhang/p/5458867.html
Copyright © 2011-2022 走看看