是否有一个编程结构的名称,您的代码看起来像一个句子?
Is there a name for a programming structure where your code will look like a sentence?
我正在寻找有关如何使代码看起来像一个句子的技术的名称。
示例:
在许多测试框架中,您可以像这样编写测试(伪代码):
expect(myObject.someNumber).toBeGreaterThan(4).toBeLessThan(7).toBeNotNull();
这个原理怎么称呼?有这方面的模式吗?谢谢!
答案由用户 "Will" 提供并且是:https://en.wikipedia.org/wiki/Fluent_interface
您在这里试图实现的目标类似于某种 Design by contract test pattern which it's not bad but if your end goal is to achieve live understandable documentation from your tests you should try some BDD,它提供了一种自然语言来定义您的测试用例,任何人都可以理解它。
我正在寻找有关如何使代码看起来像一个句子的技术的名称。
示例:
在许多测试框架中,您可以像这样编写测试(伪代码):
expect(myObject.someNumber).toBeGreaterThan(4).toBeLessThan(7).toBeNotNull();
这个原理怎么称呼?有这方面的模式吗?谢谢!
答案由用户 "Will" 提供并且是:https://en.wikipedia.org/wiki/Fluent_interface
您在这里试图实现的目标类似于某种 Design by contract test pattern which it's not bad but if your end goal is to achieve live understandable documentation from your tests you should try some BDD,它提供了一种自然语言来定义您的测试用例,任何人都可以理解它。