1.单元测试
测试了向数据库添加、删除数据,查找数据
package problem;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.*;
/**
* @author zhaomin
* @date 2020/7/11 0:08
*/
public class ProblemDAOTest {
@Test
public void selectAll() {
ProblemDAO problemDAO=new ProblemDAO();
List<Problem> problems = problemDAO.selectAll();
System.out.println(problems);
}
@Test
public void selectOne() {
ProblemDAO problemDAO=new ProblemDAO();
Problem problem = problemDAO.selectOne(1);
System.out.println(problem);
}
@Test
public void insert() {
ProblemDAO problemDAO=new ProblemDAO();
Problem problem=new Problem();
problem.setTemplateCode("111");
problem.setDescription("输出111");
problem.setLevel("简单");
problem.setTitle("输出111");
problem.setTestCode("return ”1111“");
problemDAO.insert(problem);
System.out.println(problemDAO.selectAll());
}
@Test
public void delete() {
ProblemDAO problemDAO=new ProblemDAO();
problemDAO.delete(3);
System.out.println(problemDAO.selectAll());
}
}
2.自动化测试
在FireForx浏览器下,利用xPath进行元素定位,测试了点击题目、编写代码、提交运行的功能
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get("http://123.56.73.214:8080/online-oj/index.html")
driver.find_element_by_xpath("/html/body/section[1]/div/div/div/a").click()
time.sleep(6)
driver.back()
driver.find_element_by_xpath("/html/body/section[2]/div/div[1]/div/div/table/tbody/tr[1]/td[2]/a").click()
time.sleep(4)
driver.find_element_by_xpath("/html/body/section[2]/div/div[2]/div/textarea").clear()
driver.find_element_by_xpath("/html/body/section[2]/div/div[2]/div/textarea").send_keys("public class Solution {public int addDigits(int num) {return 2;}}")
driver.find_element_by_xpath("/html/body/section[2]/div/div[2]/div/button").click()