Grammarinator是一个基于ANTLR 4的grammar文件,自动生成语句的开源项目:https://github.com/renatahodovan/grammarinator。从语言的grammar生成语句或者所谓的Fuzzy Testing,对软件测试很帮助。就像Grammarinator的README里所说,它已经帮助一些项目发现了很多缺陷。本文通过一个简单例子,让大家先了解一下它是如何安装和使用,是用来做什么的。至于背后的理论,则还需要花时间深入学习。
1.安装
Grammarinator的安装不是很复杂,以下是我在Linux Mint 19上的安装过程,主要依赖是Python3。一开始尝试用pip3安装,GitHub上说这样比较简单。但不知道为什么会报错,没安装成功。没办法还是clone源码安装吧,最后终于成功。
#Install with pip3
$ sudo apt-get install -y python-setuptools
$ pip3 install grammarinator
#Install from source
$ git clone https://github.com/renatahodovan/grammarinator.git
$ cd grammarinator
$ sudo python3 setup.py install
安装成功后应该会有两个命令,grammarinator-process
和grammarinator-generate
,自动加到你的path里。我们会在下一部分使用这两个命令,来从ANTLR的grammar文件自动生成语句。
2.使用
下面已OpenDistro SQL项目为例,