深圳外包企业网站,做公司网站和设计logo,盐城网站优化公司,京东企业网站建设思路我们想要达到的目的是模拟#xff16;#xff10;#xff10;个客户端的消息提醒功能#xff0c;当然我们没有#xff16;#xff10;#xff10;个电脑可以拿来测试#xff0c;我们只有#xff14;#xff0d;#xff15;台电脑可以用来测试#xff0c;那我们就想… 我们想要达到的目的是模拟个客户端的消息提醒功能当然我们没有个电脑可以拿来测试我们只有台电脑可以用来测试那我们就想办法在一个电脑上执行来个客户端用不通的帐户登录模拟个并发时的情况 现在遇到的问题 1:一个个登录每个电脑上登录来个用户是很繁琐的事情人都会眼花缭乱。 2:在测试过程中往往会发现一些问题这时候又需要重新部署服务器端又要部署客户端那是很要命的事情。 3:随时想测试程序性能的时候不需要别人的协助只要自己一个人是否可以顺利进行测试又轻松又快的方式是否可以总不能要求别人总加班靠自己。 解决问题的思路 先把数据库里的用户名密码都修改为有规律的密码由于我们用的是测试数据库所以密码是可以随便修改的我们编写一段程序让系统中所有的用户的密码与用户名相同由于密码在数据库里是加密的所以需要用程序脚本来设置。 在设置密码的同时我们把自动运行的脚本指令也获取了那不是一箭双雕了不是那我们就编写一段程序来实现一下这个任务。View Code //--------------------------------------------------------------------// All Rights Reserved , Copyright (C) 2011 , Hairihan TECH, Ltd. //--------------------------------------------------------------------using System.Data;using System.IO;using System.Text;namespace DotNet.Example{ using DotNet.DbUtilities; using DotNet.Manager; using DotNet.Model; using DotNet.Utilities; public class UserPassword { public void SetPassword() { // 检查密码强度默认要检查比较好系统安全性高一些 BaseSystemInfo.CheckPasswordStrength true; // 打开数据库 // IDbHelper dbHelper new OracleHelper(Data SourceKANGFU;userusercenter;passwordusercenter;); IDbHelper dbHelper new SqlHelper(Data Sourcelocalhost;Initial CatalogUserCenterV36;User Id sa ; Password Passwordsa;); dbHelper.Open(); // 批处理指令 StringBuilder Batch new StringBuilder(); // 获取用户列表,有效的,没有被删除的 BaseUserManager userManager new BaseUserManager(dbHelper); DataTable dt userManager.GetDT(BaseUserTable.FieldDeletionStateCode, 0, BaseUserTable.FieldEnabled, 1); BaseUserEntity userEntity null; foreach (DataRow dataRow in dt.Rows) { userEntity new BaseUserEntity(dataRow); // 设置密码 userManager.SetPassword(userEntity.Id.ToString(), userEntity.UserName.ToString()); Batch.AppendLine(string.Format(start D:\\DotNet.Common\\DotNet.CommonV3.6\\DotNet.WinForm\\bin\\Debug\\DotNet.WinForm.exe UserName{0} Password{1}, userEntity.UserName.ToString(), userEntity.UserName.ToString())); } dbHelper.Close(); // 将批处理写入文件 WriterFile(Batch.ToString()); } /// summary /// 将批处理写入文件 /// /summary /// param namebatch指令/param private void WriterFile(string batch) { // 把批处理结果保存到文件 string writerFileName D:\\DotNet.Common\\DotNet.CommonV3.6\\DotNet.WinForm\\bin\\Debug\\RunTest.bat; StreamWriter streamWriter new StreamWriter(writerFileName, false, Encoding.Default); streamWriter.Write(batch); streamWriter.Close(); } }} 得到的批量处理的结果如下RunTest.bat为了节省篇幅就截取一部份View Code start D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNameAdministrator PasswordAdministratorstart D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNameSystemAdmin PasswordSystemAdminstart D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNameUserAdmin PasswordUserAdminstart D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNamejiangyanxiao Passwordjiangyanxiaostart D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNamehukuangming Passwordhukuangmingstart D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNamecaoyaping Passwordcaoyapingstart D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNamegaoyufen Passwordgaoyufenstart D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNamexuqianping Passwordxuqianpingstart D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNamejianglisha Passwordjianglishastart D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNamezhuqingqing Passwordzhuqingqingstart D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNameluyizhou Passwordluyizhoustart D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNameqianleilei Passwordqianleileistart D:\DotNet.Common\DotNet.CommonV3.6\DotNet.WinForm\bin\Debug\DotNet.WinForm.exe UserNamelijia Passwordlijia 调试winform程序让程序能接受命令行参数参考代码如下View Code /// summary /// 应用程序的主入口点。 /// /summary [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // System.Console.WriteLine(WindowsIdentity.GetCurrent().Name); // 主应用程序集名 BaseSystemInfo.MainAssembly System.Reflection.Assembly.GetEntryAssembly().GetName().Name; BaseSystemInfo.StartupPath Application.StartupPath; BaseSystemInfo.AppIco Path.Combine(Application.StartupPath, Resource/Form.ico); // 获取配置信息 GetConfig(); // 这里检查是否有外部用户名密码传输进来过 if (args.Length 0) { for (int i 0; i args.Length; i) { if (args[i].ToString().StartsWith(UserName)) { BaseSystemInfo.CurrentUserName args[i].ToString().Substring(UserName.Length 1); } else if (args[i].ToString().StartsWith(Password)) { BaseSystemInfo.CurrentPassword args[i].ToString().Substring(Password.Length 1); if (BaseSystemInfo.ClientEncryptPassword) { BaseSystemInfo.CurrentPassword SecretUtil.Encrypt(BaseSystemInfo.CurrentPassword); } } // Console.WriteLine(i.ToString() : args[i].ToString()); } } if (BaseSystemInfo.MultiLanguage) { // 多语言国际化加载 ResourceManagerWrapper.Instance.LoadResources(Path.Combine(Application.StartupPath, Resource/Localization/)); // 从当前指定的语言包读取信息 AppMessage.GetLanguageResource(); } // 初始化服务 DotNetService.Instance.InitService(); // 按配置的登录页面进行登录这里需要运行的是主程序才可以 Form mainForm BaseInterfaceLogic.GetForm(BaseSystemInfo.MainAssembly, BaseSystemInfo.MainForm); Application.Run(mainForm); } 配置项目工程属性模拟输入命令行参数如下图 把程序配置为能自动登录的状态如下效果图 也可以通过手工修改配置文件的方式把 Config.xml 里的 !-- 是否自动登录默认不自动登录会好一些 -- add keyAutoLogOnvalueTrue / 也可以达到相同的效果. 万事大吉只要双击 RunTest.bat瞬间几百个客户端就自动登录能模拟多用户并发压力测试了将来做其它项目还可以反复使用不用依靠别人自己一个人就可以测试了省心省事了。 开发软件很多功能都很简单,但是一个每个功能实现好都需要几个小时时间,例如这个自动登录进行压力测试的程序也编写调试了4个小时左右, 一个软件系统往往需要成白上千的功能点,前后编写花费的时间就会很长了,需要投入很密集的劳动力. 例如我想购买一个软件,软件只有一个要求姓李的周三不能登录,姓白的周日不能登录,就这么一个软件,你需要多久能开发好? 其实他没说这个软件背后的100个需求,当你开发好了后,客户会说,怎么没有权限管理功能? 怎么没有角色管理功能? 怎么没设置密码功能? 怎么没锁定帐户功能?????????? 就像是我想购买一个进销存需要分级管理分级授权你要开价多少 其实他想要用友软件的所有功能同时也想要金蝶的所有的优点之上要结合他们自己在用的系统优点再加一个分级管理分级授权的功能所以我们做任何软件系统都需要把那些公用的基础的1000个功能点都做好了再去开发第1001个功能才好满足客户的需要。 转载于:https://www.cnblogs.com/jirigala/archive/2011/10/02/2197964.html