《软件测试实习报告(共13页).doc》由会员分享,可在线阅读,更多相关《软件测试实习报告(共13页).doc(13页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上软件测试实习报告 班级: 软件122 学号: 姓名: 孙剑峰 指导老师: 王晖 实习时间: 15.11.30-15.12.4 1、 需求分析说明书软件行业的产业化发展对软件的质量及其开发效率都提出了较高要 求,而软件测试作为软件开发项目管理中软件质量保证的关键,正发挥着越来越重要的作用,自动化测试作为提高软件测试效率的重要手段也被更多的软件开发者所 重视。本文根据Windows平台下UI自动化测试的需求,基于.NET框架,采用数据驱动模型设计并实现了一套UI自动化测试系 统。使用底层的Windows自动化测试技术通过用户界面(UI)来测试应用程序。这些技术涉及Win3
2、2API函数的调用(比如FindWindow()函数)以及向待测程序(AUT)发送Windows消息(比如WM_LBUTTONUP)。所有的Windows控件本质上都是一个窗体(window)。每个控件/窗体都有一个与之关联的句柄(handle),可以通过这个句柄来访问、操纵和检测这个控件和检测这个控件/窗体。对于轻量级的、底层的Windows窗体UI自动化测试程序来说,需要完成的工作主要有以下三类:找到目标窗体/控件的句柄操作这个窗体/控件检测这个窗体/控件2、 项目开发计划2.1、计划分项目阶段本项目分为如下部分:资料搜集:搜集关于Win32API的资料与一些官方测试资料。需求分析:分析本
3、项目的软件需求并细化。软件设计:设计软件结构。软件编写:使用不同语言编写软件。实验分析:设计数据库并进行实验。完成报告:完成最终试验测试报告。2.2、计划分项目工作内容系统阶段重点工作完成指标完成时间前期工作1. 了解Win32API2. 需求分析1. 利用官方提供进行WidowsUI2. 完成需求报告2015/12/2算法建立1. 项目设计2. 软件编写1. 完成项目设计报告书2. 编写程序2015/12/7试验测试1. 设计实验2. 结果分析1. 完成报告2015/12/83、软件设计说明书通过句柄获取待测程序的一个窗口,按钮,图标,输出设备,控件等。使用大量的Win32API调用来操作W
4、indows窗体应用程序。1. 使用System.Disgnostics.Process.Start()方法启动程序。2. 获得待测程序主窗体的句柄要获得待测程序主窗体的句柄,可使用FindWindow() Win32 API函数来解决这个问题。C#要使用Win32 API函数FindWindow(),可通过.Net平台的invoke(P/Invoke)机制,P/Invoke相关特性位于System.Runtime.InteropServices命名空间内。C#签名如下:DllImport(user32.dll, EntryPoint = FindWindow, CharSet = CharS
5、et.Auto) static extern IntPtr FindWindow(string lpClassName, string lpWindowName);3. 获得有名字控件的句柄C#签名如下:DllImport(user32.dll, EntryPoint = FindWindowEx,CharSet = CharSet.Auto)9 static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);4. 获得无名字控件的句
6、柄获得一没有名字空间的句柄,可通过隐含索引来查找相应控件。5. 发送字符给控件我们要发送一个。当按键按下时,VM_CHAR消息会发送给拥有键盘焦点的那个控件。实际上,VM_CHAR是一个Windows的常量符号,它定义为0x0102。wParam参数指定的是被按下按键的字符代码。lParam参数指定的是不同的按键状态码,比如重复次数、扫描码等。有了这些信息,就可以创建相应的C#签名: DllImport(user32.dll, EntryPoint = SendMessage, CharSet = CharSet.Auto) static extern void SendMessage1(In
7、tPtr hWnd, uint Msg, int wParam, int lParam);6、鼠标单击一个控件PostMessage()和SendMessage()的参数列表完全一致,他们的不同是:SendMessage()会等相应的Windows消息之后才会返回;PostMessage()不会。相应的C#签名:DllImport(user32.dll, EntryPoint = PostMessage, CharSet = CharSet.Auto)static extern bool PostMessage1(IntPtr hWnd, uint Msg, int wParam, int l
8、Param);7. 处理消息对话框消息对话框是一个上层(top-level)窗体,使用FindWindow()函数捕获它。8、处理菜单9、检查应用程序状态10、 使用VM_GETTEXT和SendMessage()获得控件状态4、测试用例设计设计待测窗体: 待测程序是一个用来做颜色混合的应用程序,设计的窗口如下:菜单栏的结构如下:File Edit HelpNew Cut AboutSave Copy UpdateExit Paste5、软件测试分析报告5.1 实验过程:系统:Windows10开发环境:VS20101. 安装VS2010开发环境2. 编写Form窗体,包括Textbox,Co
9、mboBox,Button,ListBox。其核心代码为: private void button1_Click(object sender, EventArgs e) string tb = textBox1.Text; string cb = comboBox1.Text; if (tb = | cb = ) MessageBox.Show(You need 2 colors, Error); else if (tb = cb) listBox1.Items.Add(Result is + tb); else if (tb = red & cb = blue | tb = blue & c
10、b = red) listBox1.Items.Add(Result is purple); else listBox1.Items.Add(Result is black); 3. 创建测试程序初始化测试程序5.2 实验结果与分析Launching application undertestWarning: process may already existForm not yet foundForm not yet foundForm has been foundMain windows handle = Finding handle to textBox1Handle to textbo
11、x1 is Handle to combox1 is Handle to button1 is Handle to listbox1 is Clicking button1Clicking away Error message boxForm has been foundTyping red and blue to applicationChecking the contents of textBox1Fetched 3charsTextBox1 contains = red Clicking on button1Checking listBox1 for purple0Test scenar
12、io result = PassHandle to menu is Handle to main help is Index to about is 265Handle to HelpItem2 is Index to HelpItem2SubItem2 is 269Exiting app in 4 seconds . . .DoneForm窗体显示为:其中,得出分析:Main windows handle = 获得textbox控件句柄成功Handle to textbox1 is 获得Form中textbox控件句柄Handle to combox1 is 获得Form中Comobox控件
13、句柄Handle to button1 is 获得Form中Button控件句柄Handle to listbox1 is 获得Form中Listbox控件句柄Listbox中显示“Result is purple”,测试代码输出“Test scenario result = Pass”表明本次WindowsUI测试成功。6、源程序测试端主要用于测试的代码为static void Main(string args) try Console.WriteLine(nLaunching application undertest); string path = D:ProjectWindowsUIT
14、estWinAppWinAppbinDebugWinApp.exe; Process p = Process.Start(path); if (p != null) Console.WriteLine(Warning: process may already exist); IntPtr mwh = FindMainWindowsHandle(Form1,100,25); Console.WriteLine(Main windows handle = + mwh); Console.WriteLine(Finding handle to textBox1); IntPtr tb = FindW
15、indowEx(mwh, IntPtr.Zero, null, ); IntPtr cb = FindWindowByIndex(mwh, 3); IntPtr butt = FindWindowEx(mwh, IntPtr.Zero, null, button1); IntPtr lb = FindWindowByIndex(mwh, 1); if (tb=IntPtr.Zero) throw new Exception(Unable to find textbox1); else Console.WriteLine(Handle to textbox1 is +tb); if (cb =
16、IntPtr.Zero) throw new Exception(Unable to find combox1); else Console.WriteLine(Handle to combox1 is + cb); if (butt = IntPtr.Zero) throw new Exception(Unable to find button1); else Console.WriteLine(Handle to button1 is + butt); if (lb = IntPtr.Zero) throw new Exception(Unable to find listbox1); e
17、lse Console.WriteLine(Handle to listbox1 is +lb); Console.WriteLine(Clicking button1); ClickOn(butt); Console.WriteLine(Clicking away Error message box); Thread.Sleep(1000); IntPtr mb = FindMessageBox(Error); if (mb = IntPtr.Zero) throw new Exception(Unable to find message box); IntPtr okButt = Find
18、WindowByIndex(mb,1); if (okButt = IntPtr.Zero) throw new Exception(Unable to find OK button); ClickOn(okButt); Console.WriteLine(Typing red and blue to application); SendChars(tb, red); Console.WriteLine(Checking the contents of textBox1); uint WM_GETTEXT = 0x000D; byte buffer = new byte256; string
19、text = null; int numFetched = SendMessage3(tb, WM_GETTEXT, 256, buffer); text = System.Text.Encoding.Unicode.GetString(buffer); Console.WriteLine(Fetched + numFetched + chars); Console.WriteLine(TextBox1 contains = + text); ClickOn(cb); SendChars(cb, bbblue); Console.WriteLine(Clicking on button1);
20、ClickOn(butt); Console.WriteLine(Checking listBox1 for purple); Thread.Sleep(2000); uint LB_FINDSTRING = 0x018F; int result = SendMessage4(lb, LB_FINDSTRING, -1,Result is purple); Console.WriteLine(result); if (result = 0) Console.WriteLine(Test scenario result = Pass); else Console.WriteLine(Test s
21、cenario result = FAIL); IntPtr hMainMenu = GetMenu(mwh); Console.WriteLine(Handle to menu is +hMainMenu); IntPtr hHelp = GetSubMenu(hMainMenu, 2); Console.WriteLine(Handle to main help is + hHelp); int iAbout = GetMenuItemID(hHelp, 0); Console.WriteLine(Index to about is + iAbout); IntPtr hSub = Get
22、SubMenu(hHelp, 2); Console.WriteLine(Handle to HelpItem2 is + hSub); int iSub = GetMenuItemID(hSub, 1); Console.WriteLine(Index to HelpItem2SubItem2 is + iSub); uint WM_COMMAND = 0x0111; /SendMessage2(mwh, WM_COMMAND, iSub, IntPtr.Zero); Console.WriteLine(Exiting app in 4 seconds . . . ); Thread.Sle
23、ep(4000); IntPtr hFile = GetSubMenu(hMainMenu, 0); ClickOn(hFile); int iExit = GetMenuItemID(hMainMenu, 2); Thread.Sleep(2000); IntPtr Exit = GetSubMenu(hMainMenu, 2); ClickOn(Exit); SendMessage2(mwh, WM_COMMAND, iExit, IntPtr.Zero); Console.WriteLine(Done); catch(Exception ex) Console.WriteLine(Fatal error: + ex.Message); Console.ReadLine(); 7、实习总结本次实习是对WindowsUI的测试实习,测试windows窗体中的个功能是否实现,因为的是的程序比较简单,整的过程完成的还是比较快的。遇到的问题也挺烦的,比如遇到的通过索引获得句柄索引表的顺序不知道,获得的句柄老是不对,测试不通过,调试的时候,老是在这个地方纠结,但最终还是解决了。专心-专注-专业
限制150内