Metro中如何实现自动测试

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

  我做的项目是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实现了自动测试一个结果集中的数据。

 

posted @ 2012-11-13 18:51  @大龙哥  阅读(696)  评论(0编辑  收藏  举报