Metro中如何实现自动测试

本文介绍了一种使用DispatcherTimer实现自动测试集合数据的方法。通过点击按钮启动测试,利用计时器每100毫秒遍历集合中的一个元素,并调用自定义方法进行验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  今天在做项目时,遇见如何自动测试一个集合中的数据,在一个已知的集合中,进行循环遍历集合中的数据,从而实现数据的测试。

  我做的项目是Windows Metro词典,所以有许多词条需要进行验证,是否有误。因此以下我就把在项目中用的一些代码分享出来。

  首先在页面中创建一个按钮,点击该按钮实现开始测试:

        private void TestButton_Click(object sender, RoutedEventArgs e)
        { 

        list = client.GetWordList("A", 114933);  //list是List<WordListItem>类型的集合,该list中有114933条记录
            DispatcherTimer timer = new DispatcherTimer();  //定义一个线程计时器
            timer.Tick+=timer_Tick;              // 超过时间间隔执行一次事件
            timer.Interval = new TimeSpan(0,0,0,0,100);   //定义时间间隔为100毫秒
            timer.Start();                   //启动计时器

        }

        void timer_Tick(object sender, object e)
        {
            DispatcherTimer timer = sender as DispatcherTimer;
            try
            {
                WordListItem item = list[index] as WordListItem;    //通过索引index进行遍历list中的数据
                SearchInputText(item);                    //进行相关的验证和处理,自定义方法
                index++;
                if (index == list.Count)
                {
                    timer.Stop();
                    Msg.Text += "ok";
                }

            }
            catch
            {
                Msg.Text += index + "-";
                timer.Stop();
            }
        }

   用到的实体对象

    public class WordListItem
    {
        public string Main { set; get; }
        public string Sub { set; get; }
        public string Time { set; get; }
        public string Count { set; get; }
    }

  以上就是使用DispatcherTimer实现了自动测试一个结果集中的数据。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值