Giter VIP home page Giter VIP logo

orthogonalarraytest's Introduction

OrthogonalArrayTest

OrthogonalArrayTest. 使用正交实验法设计测试用例,生成测试集。

1.简介

正交试验法是研究多因素、多水平的一种试验法,它是利用正交表来对试验进行设计,通过少数的试验替代全面试验,根据正交表的正交性从全面试验中挑选适量的、有代表性的点进行试验,这些有代表性的点具备了“均匀分散,整齐可比”的特点。

正交实验法设计测试用例,基本步骤如下:

  1. 提取测试需求功能说明,确定因素数和水平数
  2. 根据因素数和水平数确定n值
  3. 选择合适的正交表
  4. 根据正交表把变量的值映射到表中,设计测试用例数据集

本文参考如上步骤,使用Python实现了使用正交表自动设计测试用例的完整流程。

支持Python版本为 2.7, 3.7。

2.示例demo

输入case1,case2,case3,分别计算m(水平数),k(因素数目),n(实验次数),然后查询选择合适的正交表,裁剪最终生成相关测试集

# encoding: utf-8


from OAT import *
import json

if __name__ == "__main__":
    oat = OAT()
    case1 = OrderedDict([('K1', [0, 1]),
                         ('K2', [0, 1]),
                         ('K3', [0, 1])])

    case2 = OrderedDict([('A', ['A1', 'A2', 'A3']),
                         ('B', ['B1', 'B2', 'B3', 'B4']),
                         ('C', ['C1', 'C2', 'C3']),
                         ('D', ['D1', 'D2'])])

    case3 = OrderedDict([(u'对比度', [u'正常', u'极低', u'低', u'高', u'极高']),
                         (u'色彩效果', [u'无', u'黑白', u'棕褐色', u'负片', u'水绿色']),
                         (u'感光度', [u'自动', 100, 200, 400, 800]),
                         (u'白平衡', [u'自动', u'白炽光', u'日光', u'荧光', u'阴光']),
                         (u'照片大小', ['5M', '3M', '2M', '1M', 'VGA']),
                         (u'闪光模式', [u'开', u'关'])])

    case4 = OrderedDict([('A', ['A1', 'A2', 'A3', 'A4', 'A5', 'A6']),
                         ('B', ['B1']),
                         ('C', ['C1'])])

    print json.dumps(oat.genSets(case1))
    print json.dumps(oat.genSets(case2))
    print json.dumps(oat.genSets(case3), ensure_ascii=False)
    print json.dumps(oat.genSets(case4))
    print json.dumps(oat.genSets(case4, 1, 0))
    print json.dumps(oat.genSets(case4, 1, 1))
    print json.dumps(oat.genSets(case4, 1, 2))
    print json.dumps(oat.genSets(case4, 1, 3))

执行结果如下:

[{"K1": 0, "K2": 0, "K3": 0}, {"K1": 0, "K2": 1, "K3": 1}, {"K1": 1, "K2": 0, "K3": 1}, {"K1": 1, "K2": 1, "K3": 0}]
[{"A": "A1", "B": "B1", "C": "C1", "D": "D1"}, {"A": "A1", "B": "B2", "C": "C2", "D": "D2"}, {"A": "A1", "B": "B3", "C": "C3", "D": null}, {"A": "A1", "B": "B4", "C": null, "D": null}, {"A": "A2", "B": "B1", "C": "C2", "D": null}, {"A": "A2", "B": "B2", "C": "C1", "D": null}, {"A": "A2", "B": "B3", "C": null, "D": "D1"}, {"A": "A2", "B": "B4", "C": "C3", "D": "D2"}, {"A": "A3", "B": "B1", "C": "C3", "D": null}, {"A": "A3", "B": "B2", "C": null, "D": null}, {"A": "A3", "B": "B3", "C": "C1", "D": "D2"}, {"A": "A3", "B": "B4", "C": "C2", "D": "D1"}, {"A": null, "B": "B1", "C": null, "D": "D2"}, {"A": null, "B": "B2", "C": "C3", "D": "D1"}, {"A": null, "B": "B3", "C": "C2", "D": null}, {"A": null, "B": "B4", "C": "C1", "D": null}]
[{"对比度": "正常", "色彩效果": "无", "感光度": "自动", "白平衡": "自动", "照片大小": "5M", "闪光模式": "开"}, {"对比度": "正常", "色彩效果": "黑白", "感光度": 200, "白平衡": "荧光", "照片大小": "VGA", "闪光模式": "关"}, {"对比度": "正常", "色彩效果": "棕褐色", "感光度": 800, "白平衡": "白炽光", "照片大小": "1M", "闪光模式": null}, {"对比度": "正常", "色彩效果": "负片", "感光度": 100, "白平衡": "阴光", "照片大小": "2M", "闪光模式": null}, {"对比度": "正常", "色彩效果": "水绿色", "感光度": 400, "白平衡": "日光", "照片大小": "3M", "闪光模式": null}, {"对比度": "极低", "色彩效果": "无", "感光度": 800, "白平衡": "荧光", "照片大小": "2M", "闪光模式": null}, {"对比度": "极低", "色彩效果": "黑白", "感光度": 100, "白平衡": "白炽光", "照片大小": "3M", "闪光模式": "开"}, {"对比度": "极低", "色彩效果": "棕褐色", "感光度": 400, "白平衡": "阴光", "照片大小": "5M", "闪光模式": "关"}, {"对比度": "极低", "色彩效果": "负片", "感光度": "自动", "白平衡": "日光", "照片大小": "VGA", "闪光模式": null}, {"对比度": "极低", "色彩效果": "水绿色", "感光度": 200, "白平衡": "自动", "照片大小": "1M", "闪光模式": null}, {"对比度": "低", "色彩效果": "无", "感光度": 400, "白平衡": "白炽光", "照片大小": "VGA", "闪光模式": null}, {"对比度": "低", "色彩效果": "黑白", "感光度": "自动", "白平衡": "阴光", "照片大小": "1M", "闪光模式": null}, {"对比度": "低", "色彩效果": "棕褐色", "感光度": 200, "白平衡": "日光", "照片大小": "2M", "闪光模式": "开"}, {"对比度": "低", "色彩效果": "负片", "感光度": 800, "白平衡": "自动", "照片大小": "3M", "闪光模式": "关"}, {"对比度": "低", "色彩效果": "水绿色", "感光度": 100, "白平衡": "荧光", "照片大小": "5M", "闪光模式": null}, {"对比度": "高", "色彩效果": "无", "感光度": 200, "白平衡": "阴光", "照片大小": "3M", "闪光模式": null}, {"对比度": "高", "色彩效果": "黑白", "感光度": 800, "白平衡": "日光", "照片大小": "5M", "闪光模式": null}, {"对比度": "高", "色彩效果": "棕褐色", "感光度": 100, "白平衡": "自动", "照片大小": "VGA", "闪光模式": null}, {"对比度": "高", "色彩效果": "负片", "感光度": 400, "白平衡": "荧光", "照片大小": "1M", "闪光模式": "开"}, {"对比度": "高", "色彩效果": "水绿色", "感光度": "自动", "白平衡": "白炽光", "照片大小": "2M", "闪光模式": "关"}, {"对比度": "极高", "色彩效果": "无", "感光度": 100, "白平衡": "日光", "照片大小": "1M", "闪光模式": "关"}, {"对比度": "极高", "色彩效果": "黑白", "感光度": 400, "白平衡": "自动", "照片大小": "2M", "闪光模式": null}, {"对比度": "极高", "色彩效果": "棕褐色", "感光度": "自动", "白平衡": "荧光", "照片大小": "3M", "闪光模式": null}, {"对比度": "极高", "色彩效果": "负片", "感光度": 200, "白平衡": "白炽光", "照片大小": "5M", "闪光模式": null}, {"对比度": "极高", "色彩效果": "水绿色", "感光度": 800, "白平衡": "阴光", "照片大小": "VGA", "闪光模式": "开"}]
[{"A": "A1", "B": "B1", "C": "C1"}, {"A": "A1", "B": null, "C": null}, {"A": "A2", "B": "B1", "C": null}, {"A": "A2", "B": null, "C": null}, {"A": "A2", "B": null, "C": "C1"}, {"A": "A3", "B": "B1", "C": null}, {"A": "A3", "B": null, "C": "C1"}, {"A": "A3", "B": null, "C": null}, {"A": "A4", "B": "B1", "C": null}, {"A": "A4", "B": null, "C": null}, {"A": "A4", "B": null, "C": "C1"}, {"A": "A5", "B": "B1", "C": null}, {"A": "A5", "B": null, "C": null}, {"A": "A5", "B": null, "C": "C1"}, {"A": "A6", "B": "B1", "C": null}, {"A": "A6", "B": null, "C": null}, {"A": "A6", "B": null, "C": "C1"}, {"A": null, "B": "B1", "C": null}, {"A": null, "B": null, "C": null}, {"A": null, "B": null, "C": "C1"}]
[{"A": "A1", "B": "B1", "C": "C1"}]
[{"A": "A1", "B": "B1", "C": "C1"}, {"A": "A2", "B": "B1", "C": null}, {"A": "A2", "B": null, "C": "C1"}, {"A": "A3", "B": "B1", "C": null}, {"A": "A3", "B": null, "C": "C1"}, {"A": "A4", "B": "B1", "C": null}, {"A": "A4", "B": null, "C": "C1"}, {"A": "A5", "B": "B1", "C": null}, {"A": "A5", "B": null, "C": "C1"}, {"A": "A6", "B": "B1", "C": null}, {"A": "A6", "B": null, "C": "C1"}]
[{"A": "A1", "B": "B1", "C": "C1"}, {"A": "A1", "B": null, "C": null}, {"A": "A2", "B": "B1", "C": null}, {"A": "A2", "B": null, "C": null}, {"A": "A2", "B": null, "C": "C1"}, {"A": "A3", "B": "B1", "C": null}, {"A": "A3", "B": null, "C": "C1"}, {"A": "A3", "B": null, "C": null}, {"A": "A4", "B": "B1", "C": null}, {"A": "A4", "B": null, "C": null}, {"A": "A4", "B": null, "C": "C1"}, {"A": "A5", "B": "B1", "C": null}, {"A": "A5", "B": null, "C": null}, {"A": "A5", "B": null, "C": "C1"}, {"A": "A6", "B": "B1", "C": null}, {"A": "A6", "B": null, "C": null}, {"A": "A6", "B": null, "C": "C1"}, {"A": null, "B": "B1", "C": null}, {"A": null, "B": null, "C": "C1"}]
[{"A": "A1", "B": "B1", "C": "C1"}, {"A": "A1", "B": null, "C": null}, {"A": "A2", "B": "B1", "C": null}, {"A": "A2", "B": null, "C": null}, {"A": "A2", "B": null, "C": "C1"}, {"A": "A3", "B": "B1", "C": null}, {"A": "A3", "B": null, "C": "C1"}, {"A": "A3", "B": null, "C": null}, {"A": "A4", "B": "B1", "C": null}, {"A": "A4", "B": null, "C": null}, {"A": "A4", "B": null, "C": "C1"}, {"A": "A5", "B": "B1", "C": null}, {"A": "A5", "B": null, "C": null}, {"A": "A5", "B": null, "C": "C1"}, {"A": "A6", "B": "B1", "C": null}, {"A": "A6", "B": null, "C": null}, {"A": "A6", "B": null, "C": "C1"}, {"A": null, "B": "B1", "C": null}, {"A": null, "B": null, "C": null}, {"A": null, "B": null, "C": "C1"}]

3.后续计划

  1. 判定表查询逻辑优化
  2. 测试用例集裁剪优化

4.参考

  1. 测试用例设计-正交实验法详解: https://wenku.baidu.com/view/a54724156edb6f1aff001f79.html
  2. 用正交实验法设计测试用例:http://blog.csdn.net/fangnannanf/article/details/52813498
  3. Dr. Genichi Taguchi 设计的正交表:http://www.york.ac.uk/depts/maths/tables/orthogonal.htm
  4. Technical Support com:http://support.sas.com/techsup/technote/ts723_Designs.txt

orthogonalarraytest's People

Contributors

lovesoo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.