TDD VS BDD:REST服务 [英] TDD VS BDD: REST Service

查看:103
本文介绍了TDD VS BDD:REST服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我都对TDD与BDD感到困惑:) 在以下各点中,TDD和BDD有何不同?

I am all confused with TDD vs BDD :) How does TDD and BDD differ in each of below point?

  1. 开发:首先是测试用例,其次是开发
  2. RestService(HTTP):不进行休息电话吗?如果是这样,

  1. Development: Test case first, development follows next
  2. RestService(HTTP): Don't make rest calls? If so,

a)我们是否仅使用模拟对象返回硬编码的json?

a) do we return only hardcoded json using a mock object?

b)如何处理REST调用失败?我们也应该有测试用例吗?

b) how to handle REST call failures? We should have test case for that too?

特别是对于第2项,我在Google上搜索了很多文章,但是找不到关于如何处理休息电话的示例(代码)方法.

Especially for item 2, i have googled so many articles, but couldn't find a sample (code) approach on how to handle rest calls.

推荐答案

BDD实际上是来自TDD的,因此有点混乱也就不足为奇了! BDD与TDD完全相同(如果您要针对整个系统使用BDD,则为ATDD),但是没有单词"Test".事实证明,它可能非常强大.

BDD is actually derived from TDD, so it's not surprising there's a little confusion! BDD is exactly like TDD (or ATDD if you're doing it for a whole system), but without the word "Test". It turns out that can be pretty powerful.

特别是,它使开发人员可以与非技术业务人员就系统应该做什么进行对话.您也可以使用它与一个类或代码模块进行对话,即使是与技术专家对话也是如此.

Particularly, it lets developers have conversations with non-technical business people about what the system should do. You can also use it to have conversations about what a class should do, or a module of code should do, even with a technical expert.

因此,在您的REST服务示例中,您可以想象我是一名开发人员,并且是一位了解REST服务应该做什么的专家.

So in the example of your REST service, you can imagine that I'm a dev and you're an expert who knows what the REST service should do.

:该怎么办?
:它应该让我阅读记录.
我:太棒了!能给我一个唱片的例子吗?
:我在这里有一个...
:在任何情况下,有人不应该阅读记录吗?
:可以,如果他们没有权限.

Me: What should it do?
You: It should let me read a record.
Me: Great! Can you give me an example of a record?
You: I have one here...
Me: Is there any context in which someone shouldn't be able to read the record?
You: Sure, if they don't have permissions.

...

我:好的,我已经完成阅读,让我们进行更新.能给我一个典型更新的例子吗?
:您来了.
我:太棒了,您希望它以成功或失败来回应.在任何情况下应该会失败吗?
:好的.该记录显示了它的最后更新时间.如果与此同时其他人已经对其进行了更新,则您提交时应该会失败.

Me: Okay, so I've done Read, let's do Update. Can you give me an example of a typical update?
You: Here you go.
Me: Fantastic, and you want it to respond just with success or fail. Is there any scenario in which it should fail?
You: Sure. The record shows when it was last updated. If someone else has already updated it in the meantime, yours should fail when you submit it.

因此,您看到可以使用BDD探索各种场景,包括REST服务周围的场景.诀窍是问:你能给我一个例子吗?"然后,您将得到一个具体的示例,如果需要,可以将其自动化.对话有助于我们寻找可能遗漏的 other 个示例和方案.

So you see you can use BDD to explore all kinds of scenarios, including those around a REST service. The trick is to ask, "Can you give me an example?" Then you get a concrete example, which you can then automate if you want to. The conversations help us look for other examples and scenarios which we might have missed.

请勿使用BDD工具自动为技术用户服务!诸如Cucumber,JBehave等的BDD工具使用的是真正的英语,它比代码难重构.如果您只是在做类似REST服务的操作,请使用JUnit,NUnit等.您可以在注释中添加给出,何时,然后",或制作一些DSL.

Don't use BDD tools to automate for a technical audience! BDD tools like Cucumber, JBehave etc. work with real English that's a lot harder to refactor than code. Use JUnit, NUnit etc. if you're just doing something like a REST service. You can put "Given, When, Then" in comments, or make a little DSL.

因此,现在您可以看到由于REST调用失败而导致的故障,如果我正在对其进行编码,我将有一个类似的示例:

So now you can see that with your REST call failure, if I were coding it, I'd have an example like:

:所以,此呼叫失败...您能举个例子吗?
您:当然,如果您访问已删除的记录,它将失败.
:给我举一个可能会被删除的记录的典型示例吗?
:我们之前使用的那个很好.
我:好吧,在这种情况下,我们不应该删除记录吗?
:是的,如果它已经发布...

Me: So, this call failure... can you give me an example?
You: Sure, if you access a record that's been deleted it's going to fail.
Me: Give me a typical example of a record that might get deleted?
You: The one we're using before is good.
Me: Okay, is there a situation in which we shouldn't delete a record?
You: Yes, if it's already been published...

等等.

您可以始终看到,我并没有真正使用测试"一词.测试是BDD中不错的副产品.它更多地用于需求的探索和规范. BDD中的对话是其中最重要的部分.

You can see that throughout, I'm not really using the word "test". Tests are a nice by-product in BDD. It's used more for exploration and specification of requirements. The conversations in BDD are the most important part of it.

找到将BDD用于REST的示例很棘手的原因首先是因为REST刻意简单,并且通常没有很多行为,其次是因为BDD的场景在实现上通常没有用措辞来表达,重点在于而不是服务或系统提供的价值(读取记录").

The reason it's tricky to find examples of using BDD for REST is first because REST is deliberately simple and doesn't often have a lot of behaviour, and second because BDD's scenarios aren't generally phrased in terms of their implementation, focusing instead on the value of what the service or system provides ("read a record").

如果做得好,TDD和ATDD完全相同.就示例和场景进行对话比对测试进行对话要容易得多.

TDD and ATDD are exactly the same, if they're done well. It's just easier to have conversations about examples and scenarios than it is to have them about tests.

这篇关于TDD VS BDD:REST服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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