android UiAutomator 借助数据库查询来验证结果并记录在log中
来源:互联网 发布:孕五个月胎动知男女 编辑:程序博客网 时间:2024/06/06 00:50
如果能在测试中拿到数据库的数据来验证一下脚本执行的结果会更加佐证执行结果。借助UiAutomatorhelper调试,把查询的结果一道写入到log文件中就方便多了。本文参考了一篇博客文章对里面的代码做了一些修改。
原文地址:http://qq163230530.blog.163.com/blog/static/4289250620081186262719/
我的代码如下:比较粗糙,有具体需求了可以再详细改一下。
package mytest;import java.io.BufferedWriter;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStreamWriter;import java.sql.*;public class JEBCTest {public static void main(String[] args){String table ="", column = "";int mobile = 0;new JEBCTest(table, column, mobile);}public JEBCTest(String table, String column, int mobile) {// 驱动程序名String driver = "com.mysql.jdbc.Driver";// URL指向要访问的数据库名scutcsString url = "jdbc:mysql://192.168.1.14:3306/DZJY";// MySQL配置时的用户名String user = "root"; // MySQL配置时的密码String password = "******";System.out.println("-----------------");try {// 加载驱动程序Class.forName(driver);// 连续数据库Connection conn = DriverManager.getConnection(url, user, password);if(!conn.isClosed()) System.out.println("Succeeded connecting to the Database!");// statement用来执行SQL语句Statement statement = conn.createStatement();// 要执行的SQL语句String sql = "select * from "+ table + " where id = "+ mobile;// System.out.println(sql); // 结果集ResultSet rs = statement.executeQuery(sql); System.out.println("查询结果如下所示:");// System.out.println("" + "\t" + ""); String name = null; while(rs.next()) { // 选择列数据 name = rs.getString(column); // 输出结果 System.out.println(rs.getString("id") + "\t" + name); saveToFile(rs.getString("id") + "\t" + name, "runlog.log", false); } rs.close(); conn.close(); } catch(ClassNotFoundException e) { System.out.println("Sorry,can`t find the Driver!"); e.printStackTrace(); } catch(SQLException e) { e.printStackTrace(); } catch(Exception e) { e.printStackTrace(); } }public void saveToFile(String text, String path, boolean isClose) {File file = new File("runlog.log");BufferedWriter bf = null;try {FileOutputStream outputStream = new FileOutputStream(file, true);OutputStreamWriter outWriter = new OutputStreamWriter(outputStream);bf = new BufferedWriter(outWriter);bf.append(text);bf.newLine();bf.flush();if (isClose) {bf.close();}} catch (FileNotFoundException e1) {e1.printStackTrace();} catch (IOException e) {e.printStackTrace();}}
在调试中的代码如下:
public static void main(String[] args){new UiAutomatorHelper("Demo", "mytest.Test", "testTest", "1");new JEBCTest("users", "full_name", 545);}
0 0
- android UiAutomator 借助数据库查询来验证结果并记录在log中
- 在数据库中批量执行SQL并将结果记录到文件中
- android日志服务,将日志记录在log文件中并每天生成一个日志文件
- laravel5.4监控sql并记录在laravel.log中
- 借助 UiAutomator 实现自动 Android* 测试
- 把对数据库的查询结果封装在List中
- 把对数据库的查询结果封装在List中
- 在Android Sudio中使用Uiautomator
- 在Android Sudio中使用Uiautomator
- 在Android Sudio中使用Uiautomator
- 在spring mvc中实现JSR303验证并将验证结果传回给视图层
- 查询结果和数据库记录不一致
- android 数据库查询记录
- Java连接MySQL数据库并查询结果
- Java连接MySQL数据库并查询结果
- 查询某条记录在数据库中是 第几行
- android:查询数据库 指定列 指定列名 并输出查询结果(如查询电话本,SMS的ContentResolver提供的)
- 如何让数据库查询语句结果中不出现重复记录
- SPI和API
- ASP.NET Core MVC/WebAPi 模型绑定探索
- C# MSIL 和 闭包
- ZIPKIN 学习
- 详解ORACLE数据库的分区表
- android UiAutomator 借助数据库查询来验证结果并记录在log中
- 第七届蓝桥杯四平方和
- Spring面试:IOC和AOP的理解
- UIFramework之数据表读取工具
- Java实现简单的数据结构(五)
- centos 如何查看操作系统是哪个版本
- cocoaPod的Podfile文件的创建和内容格式
- 重新调整从左到右从上到下以"*,@"分割图纸数据
- x264 理解趣谈