Should we write only one test if a function has one behavior?

There was a private helper function, which approximately looked like this:

String format(Project project) {

return String.format("%d.internal.prefix", project.computeId());

}

We needed to use this function in a wider scope, so we agreed to move it out to another Utils file and make it a public API. Colleague made this change and wrote one test for this function:

ASSERT(format(project_with_id_123) == "123.internal.prefix")

He asked me to review the code. I requested to add more tests for this function, given that now it's a public API. What I had in mind was to write another test:

ASSERT(format(project_with_id_345) == "345.internal.prefix")

Colleague disagreed to add another test, claiming that the function has only one behavior and that we should write only one test per behavior. Somehow we got into a lengthy discussion, neither of us yielding: him refusing to write another test, me refusing to approve the code.

So my questions are:

– How do we count a number of behaviors a function has?

– Is there a practice that there should be only one test per behavior? If yes, what is the rationality for this practice?

– If we write only a single test, wouldn't the simpler function returning the hardcoded expected output

i.e:

String format(Project project) { return "123.internal.prefix" }

make all tests pass (because in this case there is only one test)?

submitted by /u/mercury0114
[link] [comments]

from Software Development – methodologies, techniques, and tools. Covering Agile, RUP, Waterfall + more! https://ift.tt/Jj7u2SU

Leave a comment

Design a site like this with WordPress.com
Get started
search previous next tag category expand menu location phone mail time cart zoom edit close