public static void makeByDB() { SqlSession session = DB.getSession(); RunnersMapper runMap = session.getMapper(RunnersMapper.class); RequestsMapper requestMap = session.getMapper(RequestsMapper.class); for (Sets set : runMap.getSets("wait")) { List<Requests> requests = runMap.getRequests(set.getId()); for (Requests request : requests) { List<String> fields = new ArrayList<String>(); int i = 0; for (Fields field : requestMap.getFields(request.getId())) { fields.add(field.getName()); } Make.makeRequest(request.getName(), fields); Make.makeExcel(request.getName(), fields); } } }
public static void makeRun() { String runPath = "/data1/www/autotest/src/com/autotest/run/run.java"; if (System.getProperties().getProperty("os.name").toUpperCase().contains("WINDOW")) { runPath = System.getProperty("user.dir") + "\\src\\com\\autotest\\run\\run.java"; } File run = new File(runPath); String contentLeft = "package com.autotest.run;\n"; String importContent = "import org.junit.Rule;\n" + "import org.junit.Test;\n" + "import com.autotest.annotation.DataSource;\n" + "import com.autotest.core.DriverService;\n" + "import com.autotest.core.sendHttp;\n" + "import com.autotest.enums.DataType;\n" + "import com.autotest.enums.DriverType;\n" + "import com.autotest.entity.request.*;\n"; String contentClass = "public class run {\n" + "@Rule\n" + "public DriverService ds=new DriverService();\n"; String contentRight = "}"; String content = ""; SqlSession session = DB.getSession(); RunnersMapper runMap = session.getMapper(RunnersMapper.class); RequestsMapper requestsMap = session.getMapper(RequestsMapper.class); for (Sets set : runMap.getSets("wait")) { String driverType = "Drive=DriverType.excel"; String dataType = "minmax=DataType.min"; if (set.getDrivertype() == 1) { driverType = "Drive=DriverType.constant"; dataType = "count=" + set.getDatatype(); } else { if (set.getDatatype() == 1) { dataType = "minmax=DataType.max"; } } content = content + "@Test\n" + "@DataSource(" + driverType + "," + dataType + ")\n" + "public void " + set.getName() + "(){\n"; for (Requests request : runMap.getRequests(set.getId())) { content = content + "new sendHttp().send(new ReqEntity_" + request.getName() + "());\n"; } content = content + "}\n"; } String txt = contentLeft + importContent + contentClass + content + contentRight; try { run.createNewFile(); FileOutputStream out = new FileOutputStream(run); out.write(txt.getBytes("GBK")); out.close(); } catch (Exception e) { System.out.println("生成run类失败," + e.getMessage()); e.printStackTrace(); } }