Java API 搜索引擎项目的测试

注:①此项目不支持模糊搜索的功能,所以如果要查找一个 API 必须准确的输入才能被查找到。②我看了一下官方文档,最短的 API 长度为 3 ,最长的 API 这里先不考虑。

一、功能测试

1.等价类和边界值划分:

有效等价类

无效等价类

三位及三位以上英文字符

三位以下英文字符;
数字字符;
中文字符;
别的特殊字符。

2.设计测试用例:

测试用例

期望结果

ArrayList

能被查找到并正确的显示到页面上

(不输入任何字符)

查找不到内容

a

查找不到内容

,,,,,,,

查找不到内容

a,,,

查找不到内容

aaaaaaa

查找不到内容

123

查找不到内容

链表

查找不到内容

二、单元测试

单元测试我是在开发阶段在 IDEA 中创建测试类进行测试。

1.测试 Parser 类:

public class ParserTest {
    @Test
    public void convertLine() throws IOException {
        Parser parser = new Parser();
        File file = new File("D:\\javaSE8 Doc\\docs\\api\\java\\math\\BigInteger.html");
        String res = parser.convertLine(file);
        System.out.println(res);
    }
    @Test
    public void convertContent() throws IOException {
        File file = new File("D:\\Test.txt");
        Parser parser = new Parser();
        String res = parser.convertContent(file);
        System.out.println(res);
    }
    @Test
    public void convertUrl() {
        File file = new File("D:\\javaSE8 Doc\\docs\\api\\EntityResolver.html");
        Parser parser = new Parser();
        String res = parser.convertUrl(file);
        System.out.println(res);
    }
    @Test
    public void convertTitle() {
        File file = new File("D:\\javaSE8 Doc\\docs\\api\\EntityResolver.html");
        Parser parser = new Parser();
        String res = parser.convertTitle(file);
        System.out.println(res);
    }
}

2.测试 Index 类:

public class IndexTest {

    @Test
    public void getDocInfo() throws IOException {
        Index index = new Index();
        index.build("D:\\data.txt");
        Index.Weight weight = new Index.Weight();
        DocInfo docInfo = index.getDocInfo(weight.docId);
        System.out.println(docInfo);

    }

    @Test
    public void getInverted() throws IOException {
        Index index = new Index();
        index.build("D:\\data.txt");
        List<Index.Weight> weights = index.getInverted("arraylist");
        for (Index.Weight weight : weights) {
            System.out.println(weight.docId);
            System.out.println(weight.word);
            System.out.println(weight.weight);
            System.out.println();
        }
    }
}

3.测试 Searcher 类:

public class SearcherTest {

    @Test
    public void search() throws IOException {
        Searcher searcher = new Searcher();
        List<Result> res = searcher.search("arraylist");
        for (Result result : res) {
            System.out.println();
            System.out.println("=============================================");
            System.out.println();
            System.out.println(result);
        }
    }
}

三、兼容性测试

我分别在 Chrome、Firefox、IE 浏览器和手机上进行测试的,测试结果如下:

1.Chrome 浏览器能正常显示 HTML 页面并能进行搜索。

谷歌

2.Firefox 浏览器也能正常显示 HTML 页面并能进行搜索。

image

3. IE 浏览器页面显示异常,并且无法进行搜索。

image

4.手机端使用的是 QQ 内置浏览器进行测试的,能正常显示页面并能进行搜索。

Screenshot_20200729_224450_com.tencent.mobileqq

四、自动化测试

自动化测试使用的是 unittest 框架写的脚本,并将运行结果生成 HTML 报告:

from selenium import webdriver
import unittest
import time

class imageTest(unittest.TestCase):#定义的类
    def setUp(self):#初始化
         self.driver = webdriver.Chrome()
        self.driver.get("http://39.97.104.31:8080/docSearcher/")
        self.driver.maximize_window()
        time.sleep(3)

    def test_mytest(self):#测试的方法必须以 'test_' 开头
        self.driver.find_element_by_xpath("//*[@id='app']/div[2]/input").send_keys("arraylist")
        time.sleep(3)
        self.driver.find_element_by_xpath("//*[@id='app']/div[2]/button").click()
        time.sleep(3)
        self.driver.find_element_by_xpath("//*[@id='app']/div[3]/div[1]/a").click()
        time.sleep(3)

    def tearDown(self):#清理测试环境
        self.driver.quit()#close 也可以,但是 quit 可以清理掉缓存


if __name__ == "__main__":
    unittest.main()
image

猜你喜欢

转载自blog.51cto.com/14298563/2514710
今日推荐