Language agnostic 从文档的角度来看,通过测试用例组织功能相同的断言是必要的
我正在努力完善我的BDD实践,我已经解决了这个问题。下面是一个简单的数据结构类(为简洁起见,将其精简): 我用一些伪语言对它进行了以下测试:Language agnostic 从文档的角度来看,通过测试用例组织功能相同的断言是必要的,language-agnostic,naming-conventions,bdd,methodology,Language Agnostic,Naming Conventions,Bdd,Methodology,我正在努力完善我的BDD实践,我已经解决了这个问题。下面是一个简单的数据结构类(为简洁起见,将其精简): 我用一些伪语言对它进行了以下测试: # "describe" are test suites # "it" are test cases # "when" are subtests describe geometry: describe constructor: it creates geometry object: expect `Geom
# "describe" are test suites
# "it" are test cases
# "when" are subtests
describe geometry:
describe constructor:
it creates geometry object:
expect `Geometry(cnt = 390487680, bps = 512)` to be instance of
Geometry class
describe bytes per sector argument:
it is required:
when given:
expect `Geometry(cnt = 390487680, bps = 512)` not to raise
when missing:
expect `Geometry(cnt = 390487680)` to raise TypeError
it is okay (???):
expect each of these not to raise:
# lower bound
`Geometry(cnt = 390487680, bps = 1)`
# higher bound
`Geometry(cnt = 390487680, bps = 65535)`
# non-power of 2
`Geometry(cnt = 390487680, bps = 42)`
# odd
`Geometry(cnt = 390487680, bps = 123)`
# typical
`Geometry(cnt = 390487680, bps = 512)`
# advanced format
`Geometry(cnt = 390487680, bps = 4096)`
it cannot be zero:
expect `Geometry(cnt = 390487680, bps = 0)` to raise ValueError
it cannot be negative:
expect each of these to raise ValueError:
`Geometry(cnt = 390487680, bps = -1)`
`Geometry(cnt = 390487680, bps = -512)`
`Geometry(cnt = 390487680, bps = -4096)`
it cannot be larger than 16 bits:
expect `Geometry(cnt = 390487680, bps = 65535)` not to raise
expect each of these to raise ValueError:
`Geometry(cnt = 390487680, bps = 65536)`
`Geometry(cnt = 390487680, bps = 65537)`
`Geometry(cnt = 390487680, bps = 100000)`
it cannot be of wrong type:
expect each of these to raise TypeError:
when float:
`Geometry(cnt = 390487680, bps = 3.14)`
`Geometry(cnt = 390487680, bps = -3.14)`
when string:
`Geometry(cnt = 390487680, bps = '512')`
`Geometry(cnt = 390487680, bps = '')`
when none:
`Geometry(cnt = 390487680, bps = None)`
when list:
`Geometry(cnt = 390487680, bps = [])`
`Geometry(cnt = 390487680, bps = [512])`
when tuple:
`Geometry(cnt = 390487680, bps = ())`
`Geometry(cnt = 390487680, bps = (512, ))`
when dict:
`Geometry(cnt = 390487680, bps = {})`
`Geometry(cnt = 390487680, bps = {512: 1024})`
我不知道如何处理这没关系
测试。实际实现并不能真正区分非二次幂、奇数和其他类型的数字,所以我不妨添加一些类似“素数也很好”的检查
然而,尽管从代码的角度来看几乎是无用的,但我尝试以这种方式设计测试用例,以便它们也可以作为读者的附加示例。我想,通过这种方式,读者可以了解到我的代码可以容忍奇怪的扇区大小,所以这些断言可能并没有那个么大的用处
因此,在这种背景下,我想知道的是:
在BDD中设计正向分支测试用例时,是否应在单个测试用例下将所有功能相同的断言分组:
it should be okay:
# lower bound
`Geometry(cnt = 390487680, bps = 1)`
# higher bound
`Geometry(cnt = 390487680, bps = 65535)`
# odd
`Geometry(cnt = 390487680, bps = 123)`
...
或者应该在自己的测试用例中分离每个功能相同的期望
it should not fail given lower bound:
`Geometry(cnt = 390487680, bps = 1)`
it should not fail given upper bound:
`Geometry(cnt = 390487680, bps = 65535)`
it should not fail given odd value:
`Geometry(cnt = 390487680, bps = 123)`
当我在上面的时候,对于组合阳性分支测试用例,什么是正确的、普遍理解的措辞?我想这不是“应该没事的”,对吧
it should not fail given lower bound:
`Geometry(cnt = 390487680, bps = 1)`
it should not fail given upper bound:
`Geometry(cnt = 390487680, bps = 65535)`
it should not fail given odd value:
`Geometry(cnt = 390487680, bps = 123)`