开发一个单元测试API [英] developing a unit testing API

查看:139
本文介绍了开发一个单元测试API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好, 我被分配探索利用市场上现有的工具进行单元测试的任务。我的问题是我如何写一个API,将以书面单元测试用例帮助。 例如,我可以把NUnit来写这样的事情,以检查是否文件存在于指定的位置。

I have been assigned a task of exploring unit testing using tools available in the market. My question is how do i write an API that would help in writing unit test cases. Example i can use nunit to write something like this to check whether file exists in the given location.

<Test()> _
   Public Sub CheckOutputFileInfo()
    ReportPath = "D:temp\test.txt"
    Dim result As Boolean
    result = File.Exists(ReportPath)
    Assert.IsTrue(result)
End Sub

我明白这不是最好的例子,但我的问题是我如何NUnit的整合和发展的API,以便其他开发/测试人员可以编写测试用例,而不理会了解NUnit的。 仅供参考我从来没有写过一个API,这将是我在这第一枪。 从哪里开始?任何建议 谢谢

I understand this is not the best example but my question is how do i incorporate nunit and develop an API so that other developers/testers can write test cases without bothering about to learn about nunit. FYI I have never written an API this will be my first shot at it. Any recommendations on where to start?? thanks

推荐答案

您的例子并不是严格意义上的单元测试,因为它击中的文件系统。

Your example isn't strictly a unit test as it hits the file system.

一个测试是不是一个单元测试,如果:

A test is not a unit test if:

  1. 它谈论到数据库
  2. 它在网络上
  3. 通信
  4. 倒是文件系统
  5. 在它不能在同一时间为您的任何其他单元测试运行
  6. 您需要做特别的东西到你的环境(如编辑配置文件)来运行它。

我会建议你学习单元测试最佳实践和模式开始尝试让你的开发人员开始单元测试之前。从以往的经验,需要有人有充分的冠军单元测试抓住它自己。这将节省您的长远许多烦恼。

I would advise you learn Unit Test best practices and patterns before starting to try to make your developers start unit testing. From experience someone needs to champion unit testing having fully grasped it themselves. It will save you a lot of headaches in the long run.

下面是一个很好的书,让你开始:

Here is an excellent book to get you started:

http://artofunittesting.com/

这篇关于开发一个单元测试API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆