1, Data code separation, convenient maintenance.
The general practice is to save the data in Excel, which is read by the program.
2. Read Excel data.
The new Excel,a column in the D-Disk url,b the column-drop parameters.
New Class Redexcel
PackageCOM.LX;ImportJava.io.File;Importjava.io.IOException;ImportJxl.*; Importjxl.read.biff.BiffException; Public classredexcel{ Public Static voidMain (string[] args)throwsbiffexception, IOException {//reading data from coordinates B1 in a documentSystem.out.println (Getexceldata ("D:\\apitest.xls", 2, 1)); } /** Get data for Excel documents according to path and coordinates * parameter description: path (Excel document Path), x (x coordinate), y (y coordinate) **/ Public StaticString Getexceldata (String path,intXintYthrowsbiffexception, ioexception{Workbook book; Sheet Sheet; Cell cell1; String str; Book= Workbook.getworkbook (NewFile (path)); Sheet= Book.getsheet (0); Cell1= Sheet.getcell (X-1, y-1); STR=cell1.getcontents (); returnstr; }}
3, read the data, send the request
@Test publicvoidthrows biffexception, IOException { System.out.println ("test1"); = Redexcel.getexceldata ("D:\\a.xls", 1, 1); = Redexcel.getexceldata ("D:\\a.xls", 2, 1); = httprequest.sendget (URL, data); System.out.println (s); Asserttrue (S.indexof ("and")!=-1); }
Interface Test (Java+testng+ant+jenkins) Fifth Java II