51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2367|回复: 1

基于 Docker 集群的分布式测试系统 DDT (DockerDistributedTest) 【上】

[复制链接]

该用户从未签到

发表于 2017-8-9 11:56:04 | 显示全部楼层 |阅读模式
本帖最后由 八戒你干嘛 于 2017-8-9 14:56 编辑

1.背景

当自动化用例累积的越来越多,回归自动化用例的时间越来越长。我们往往会选择使用多线程的方式来跑用例集,但是用例数量达到一定数量级(千级以上)后,在单台机器上使用多线程(千级以上)直接影响到机器性能,能不能组成并行加并发的模式跑用例,自动将用例集拆分成更细粒度的子集,将子集在单独的容器(容器可以部署在多台机器上)内并发执行。

1-1.业内工具调研Selenium grid

Selenium grid, JMeter都是在自身的工具内实现分布式测试,通用性较差;HadoopUnit不得不说用大数据的思维来处理分布式测试,在2011年就有这种想法还是很前卫的;由于Docker的便利,现在开发的生产环境已开始大规模使用,而自动化测试领域也必将有这个趋势。

1-2.DockerDistributedTest

最终形成了基于Docker集群的分布式测试系统DDT(DockerDistributedTest);该系统使用Docker容器作为子集的执行容器,Docker镜像中打包了用例所需运行环境(Java环境)、测试工程及分布式组件TaskTrack,并将测试工程依赖的jar包挂载到Docker容器中。

2.摸索2-1.用例执行的方式

用例使用TestNG编写,maven的Surefire测试插件封装了很多执行TestNG和JUnit用例的方法,但是执行mvn命令会输出很多stdout, 同时在新启动的Docker容器内执行mvn命令,会根据pom.xml去download一些依赖的jar,这样就增加了执行用例的前期时间,虽然方法很便捷,但是耗时相对会增加;

故直接使用TestNG命令行,使用TestNG命令需要指定classpath, 我们将实体机中测试工程依赖的jar目录挂载到Docker容器中,TestNG直接依赖classpath, 直接运行TestNG命令跑用例。  获取maven工程依赖的jar包可以通过如下方式获取:

  1. mvn dependency:copy-dependencies -DoutputDirectory=/data1/hugang/docker-distributedtest/docker-addresource/lib_path
复制代码

启动单个docker容器时,使用-v将测试工程依赖的jar包挂载到容器中:

  1. docker run -d --net=host -v /data1/hugang/docker-distributedtest/docker-addresource/lib_path:/lib_path  -it docker-distributed-self
复制代码
每个docker容器使用TestNG命令执行测试用例:
  1. java -classpath '/FastTest/target/test-classes/:/lib_path/*' org.testng.TestNG -parallel methods -testclass com.weibo.qa.testcase.strategy.测试类1,测试类2,..
复制代码
其中:/FastTest/target/test-classes/ 为测试工程FastTest的class文件目录;可以通过mvn clean test-compile生成。/lib_path/* 为测试工程中依赖的jar包。-parallel methods:方法级并发执行


org.testng.TestNG使用参数:
Usage: <main class> [options] The XML suite files to run  Options:    -configfailurepolicy              Configuration failure policy (skip or continue)   
-d                                Output directory   
-dataproviderthreadcount          Number of threads to use when running data providers   
-excludegroups                    Comma-separated list of group names to  exclude   
-groups                           Comma-separated list of group names to be run   
-junit                            JUnit mode (default: false)   
-listener                         List of .class files or list of class names implementing ITestListener or ISuiteListener   
-log, -verbose                    Level of verbosity   
-methods                          Comma separated of test methods (default: [])   
-methodselectors                  List of .class files or list of class names implementing IMethodSelector   
-mixed                            Mixed mode - autodetect the type of current test and run it with appropriate runner (default: false)   
-objectfactory                    List of .class files or list of class names implementing ITestRunnerFactory   
-parallel                         Parallel mode (methods, tests or classes)   
-port                             The port   
-reporter                         Extended configuration for custom report listener   
-suitename                        Default name of test suite, if not specified in suite definition file or source code   
-suitethreadpoolsize              Size of the thread pool to use to run suites (default: 1)   
-testclass                        The list of test classes   
-testjar                          A jar file containing the tests   
-testname                         Default name of test, if not specified in suitedefinition file or source code   
-testnames                        The list of test names to run   
-testrunfactory, -testRunFactory  The factory used to create tests   
-threadcount                      Number of threads to use when running tests in parallel   
-usedefaultlisteners              Whether to use the default listeners (default: true)   
-xmlpathinjar                     The full path to the xml file inside the jar file (only valid if -testjar was specified) (default: testng.xml)

请跳转至
基于 Docker 集群的分布式测试系统 DDT (DockerDistributedTest) 【中】

回复

使用道具 举报

该用户从未签到

发表于 2017-8-9 15:05:05 | 显示全部楼层
当年我们也是在做一个类似的项目,用Docker来做分布式的执行引擎,我们维护了一个简化支持分布式的TestNG的版本。由于把序列化的部分给注释掉了,所以我们是每一个slave contaienr会生成一个result.xml,然后通过一个脚本把这些小的xml合并成一个大的xml,再交给Jenkins来解析,我目前正在带团队做一个全新的分布式测试平台。这个是我们那个时候维护的TestNG 版本https://github.com/TestFoundry/testng,有兴趣的同学可以参考。
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-3-29 20:02 , Processed in 0.068227 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表