加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何测试方法(白盒测试)

发布时间:2020-12-16 01:50:39 所属栏目:百科 来源:网络整理
导读:这是我想测试的方法 private static void selectTop20Tags(Dictionarystring,int list) { //Outputs the top 20 most common hashtags in descending order foreach (KeyValuePairstring,int pair in list.OrderByDescending(key = key.Value).Take(20)) { C
这是我想测试的方法

private static void selectTop20Tags(Dictionary<string,int> list)
    {

         //Outputs the top 20 most common hashtags in descending order
         foreach (KeyValuePair<string,int> pair in list.OrderByDescending(key => key.Value).Take(20))
         {
             Console.WriteLine("{0},{1}",pair.Key,pair.Value);
         }

    }

我不知道我将如何测试这一点,我一直在研究它并尝试各种各样的东西,但无法让它工作.

我想要包括一些代码,比如

#if TEST
            if ((length of list don't know how you would do it) <= 20)
            {
                StreamWriter log2;
                // appends file
                log2 = File.AppendText("logOfTests.txt");
                // Writes to the file
                log2.WriteLine("PASS");
                log2.WriteLine();

                // Closes the stream
                log2.Close();
            }
#endif

我想我只需要看一个例子,我就会知道.

解决方法

我建议学习单元测试.阅读MSDN上的 this文章,并在Google上搜索如何编写单元测试.它们是测试单个代码单元的好方法,因此应该适合您的情况.

我还建议分离出与UI相关的代码,例如对MessageBox的调用,其他UI元素和Console;来自您要测试的代码.这将使测试代码的逻辑和执行变得更加容易.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读