用新的编程语言实现 xunit

发布于 2024-07-06 22:48:37 字数 169 浏览 10 评论 0原文

我们中的一些人仍然“生活”在尚未接受单元测试的编程环境中。 首先,显而易见的第一步是尝试实现一个像样的单元测试框架,我猜 xUnit 是“标准”。

那么,以新的编程语言实现 xUnit 的良好起点是什么?

顺便说一句,因为人们在问:我的目标环境是 Visual Dataflex。

Some of us still "live" in a programming environment where unit testing has not yet been embraced. To get started, the obvious first step would be to try to implement a decent framework for unit testing, and I guess xUnit is the "standard".

So what is a good starting point for implementing xUnit in a new programming language?

BTW, since people are asking: My target environment is Visual Dataflex.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

陈独秀 2024-07-13 22:48:37

它适用于哪种语言 - 已经有很多了

Which language is it for - there are quite a few in place already.

寒冷纷飞旳雪 2024-07-13 22:48:37

如果这阻止您开始编写单元测试,您可以在没有测试框架的情况下开始。

C 风格语言的示例:

void Main() 
{
  var algorithmToTest = MyUniversalQuestionSolver();
  var question = Answer to { Life, Universe && Everything };

  var actual = algorithmToTest(question);
  var expected = 42;
  if (actual != expected) Error();

  // ... add a bunch of tests
}

Cobol 风格语言的示例:

MAIN.
  COMPUTE EXPECTED_ANSWER = 42
  SOLVE ANSWER_TO_EVERYTHING GIVING ACTUAL_ANSWER
  SUBTRACT ACTUAL_ANSWER FROM EXPECTED_ANSWER GIVING DIFFERENCE
  IF DIFFERENCE NOT.EQ 0 THEN
    DISPLAY "ERROR!"
  END-IF

  * ... add a bunch of tests
  STOP RUN

完成代码更改(并且可能编译)后运行 Main。 每当有人向您的存储库提交代码时,就在服务器上运行 main。

当您着迷时,请更多地寻找框架,或者看看您是否可以将 Main 中的一些部分分解到您自己的框架中。

If this is stopping you from getting started with writing unit tests you could start out without a testing framework.

Example in C-style language:

void Main() 
{
  var algorithmToTest = MyUniversalQuestionSolver();
  var question = Answer to { Life, Universe && Everything };

  var actual = algorithmToTest(question);
  var expected = 42;
  if (actual != expected) Error();

  // ... add a bunch of tests
}

Example in Cobol-style language:

MAIN.
  COMPUTE EXPECTED_ANSWER = 42
  SOLVE ANSWER_TO_EVERYTHING GIVING ACTUAL_ANSWER
  SUBTRACT ACTUAL_ANSWER FROM EXPECTED_ANSWER GIVING DIFFERENCE
  IF DIFFERENCE NOT.EQ 0 THEN
    DISPLAY "ERROR!"
  END-IF

  * ... add a bunch of tests
  STOP RUN

Run Main after you are finished with a changed (and possibly compile) on your code. Run main on the server whenever someone submits code to your repository.

When you get hooked, Look more for a framework or see if you possibly could factor out some of the bits from Main to your own framework.

最单纯的乌龟 2024-07-13 22:48:37

我建议一个好的起点是在其他几种语言上使用 xunit,以了解这种类型的单元测试框架的工作原理。 然后,您需要深入研究该行为,并开始研究如何以适合您的新语言的方式重新创建该行为。

I'd suggest that a good starting point would be to use xunit on a couple of other languages to get a feel for how this style of unit test framework works. Then you'll need to go in depth into the behaviour and start working out how to recreate that behaviour in a way that fits with your new language.

冷默言语 2024-07-13 22:48:37

我根据 测试驱动开发中的代码在 VFP 中创建了一个不错的单元测试框架:实用指南,作者:David Astels。 通过阅读示例、理解技术并将 Java 代码翻译成您的语言,您将会受益匪浅。

I created a decent unit test framework in VFP by basing it on the code in Test Driven Development: A Practical Guide, by David Astels. You'll get a long way by reading through the examples, understanding the techniques and translating the Java code into your language.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文