我对贸易和发展会议来说是很新的。 我读到。 TDD, Example , 并说“凡试图用同一不变值表示不止一件事” ,它就展示了 Plus(
)。
我认为,加一(1,1)与加一(1,2)之间没有区别,后者使用同样的固定价值。 我想知道在测试方法中使用同样的固定价值有什么利弊?
我对贸易和发展会议来说是很新的。 我读到。 TDD, Example , 并说“凡试图用同一不变值表示不止一件事” ,它就展示了 Plus(
)。
我认为,加一(1,1)与加一(1,2)之间没有区别,后者使用同样的固定价值。 我想知道在测试方法中使用同样的固定价值有什么利弊?
我认为你错误地解释这一说法。 作者(ho)试图表达的是,以下法典是灾害的对应法。
const SomeRandomValue = 32;
...
// Plus testcase
Plus(SomeRandomValue, SomeRandomValue)
...
// Divide testcase
Divide(SomeRandomValue, SomeRandomValue)
你们有两个试样,用none descriptive不变。 无法知道,通过将<代码>SomeRandomValue改为0
,你的测试程序将失败。
更好的点名会像这样。
const AdditionValue = 32;
const DivisorValue = 32;
...
// Plus testcase
Plus(AdditionValue, AdditionValue)
...
// Divide testcase
Divide(DivisorValue, DivisorValue)
在什么地方,对固定装置的使用应当显而易见。 您在创建试验场时不应再使用密码。
或用其他词语表述:
I don t see anything wrong with reusing the
DivisorValue
constant in multiple testcases > but there is definitly something wrong trying to shoehorn one value into a none descriptive variable just in the name of code reuse.
如果你在测试中使用同样的价值——如<条码>+(1、1)条码>——那么你的代码就可出于错误原因发挥作用。 此处采用<代码> 附加<<>><>>>>>,通过这种测试,但测试结果不同。
public int Plus (int a, int b) {
return a + a;
}
A test that avoids this risk is a better test than one which lets errors like these slip through.
I m working in a team of 2 front-end developers on a web-based late-stage startup project. The site works quite well, but there s a lot of room for improvement code-wise, as the code is quite messy ...
I ve read a lot about Test-Driven Development (TDD) and I find the principles very compelling, based on personal experience. At the moment I m developing a website for a start-up project I m involved ...
I have a function which opens up the help file for the app. The function takes 3 arguments : ShowHelp(appPath, 1, @"heelphelp.doc") The first argument is the start path. The second argument is ...
Just to clear the air, I am not some cruel factory master trying to silence working ladies. I am having a very annoying problem where when using Thoughtbot s factory girl in my specs, every time ...
My company is fairly new to unit testing our code. I ve been reading about TDD and unit testing for some time and am convinced of their value. I ve attempted to convince our team that TDD is worth ...
I m trying to get my head round Unit Testing and there s one more piece of the jigsaw I need to find. What I m trying to do is write tests for the following code. In this case, I ve got a really ...
How can I test a private method of an abstract class using reflection (using C#)? I am specifically interested in adapting the code found in this thread. I am aware of the discussion around the ...
Testing the Equals method is pretty much straight forward (as far as I know). But how on earth do you test the GetHashCode method?