游戏测试之接口工具篇(下篇)

发表于:2016-10-28 11:18

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:煎饼的博客    来源:51Testing软件测试网采编

分享:
  测试工具UI
  UI界面选择了Unity古老的OnGUI方法,原因就是:易学,够用。下边是一个简单的GUI界面。
using UnityEngine;
public class TestUI : MonoBehaviour {
private Rect windowRect = new Rect(Screen.width * 0.25f, 0, Screen.width / 2, Screen.height - 10);
public Vector2 scrollPosition = Vector2.zero;
void OnGUI() {
windowRect = GUI.Window(0, windowRect, WindowFunction, "接口测试工具");
}
void WindowFunction(int windowID) {
GUI.DragWindow(new Rect(0, 0, Screen.width/2, 30));
GUI.Box(new Rect(0,0,Screen.width,Screen.height),"");
GUILayout.BeginArea(new Rect(5, 20, Screen.width / 2-20, Screen.height));
scrollPosition = GUILayout.BeginScrollView(scrollPosition,GUILayout.Width(Screen.width / 2 - 20),GUILayout.Height(Screen.height-60));
// 在这里请求列表解析
GUILayout.EndScrollView();
GUILayout.BeginHorizontal();
if (GUILayout.Button("统计数量")) {
}
if (GUILayout.Button("清空记录")) {
}
if (GUILayout.Button("录制")) {
}
if (GUILayout.Button("停止")) {
}
GUILayout.EndHorizontal();
GUILayout.EndArea();
}
}
  效果图:
  参数列表解析
  参数列表是一个object类型的数组,所以里边可以放各种基础类型,解析的时候,需要用到反射,动态修改里边的内容,解析函数如下:
public void ParseBaseType2(object aParam, object aList, int index = 0) {
GUILayout.BeginHorizontal();
Type paramType = aParam.GetType();
if (paramType == typeof(string)) {
GUILayout.Label("String", GUILayout.Width(30));
aParam = GUILayout.TextField(aParam.ToString());
} else if (paramType == typeof(short)) {
GUILayout.Label("Short", GUILayout.Width(30));
aParam = Convert.ToInt16(GUILayout.TextField(aParam.ToString()));
} else if (paramType == typeof(int)) {
GUILayout.Label("Int", GUILayout.Width(30));
aParam = Convert.ToInt32(GUILayout.TextField(aParam.ToString()));
} else if (paramType == typeof(long)) {
GUILayout.Label("Long", GUILayout.Width(30));
aParam = Convert.ToInt64(GUILayout.TextField(aParam.ToString()));
} else if (paramType == typeof(bool)) {
GUILayout.Label("Bool", GUILayout.Width(30));
aParam = Convert.ToBoolean(GUILayout.TextField(aParam.ToString()));
} else {
GUILayout.Label("type can not parse,type is " + paramType.Name);
GUILayout.EndHorizontal();
return;
}
var removeAtMethod = aList.GetType().GetMethod("RemoveAt");
removeAtMethod.Invoke(aList, new object[] { index });
var insertMethod = aList.GetType().GetMethod("Insert");
insertMethod.Invoke(aList, new object[] { index, aParam });
GUILayout.EndHorizontal();
}
  最终成品图:
  项目4
  SLG手游,依旧Socket通讯,依旧PB。
  在上一个接口工具的基础上,新增了:
  更详细的用例设计和用例库的读取和保存(使用C#的序列化)
  增加自动化接口测试模块,测试结果通过Http请求发送到Web服务器
  增加一个Web服务器接收测试结果并进行统计(使用Flask搭建),测试结果用图表形式展示(Echarts)
  Coding,Coding~
相关文章:
游戏测试之接口工具篇(上篇)
22/2<12
100家互联网大公司java笔试题汇总,填问卷领取~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2023
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号