Linked Questions

1
vote
3answers
1k views

Should all possible counter-cases be tested? [duplicate]

I'm currently trying to unit test a behavior which, in some very particular cases, returns B instead of A. It may depend on the value of 3 different attributes for example. How should I test this? ...
1
vote
1answer
2k views

Multiple methods in single test case [duplicate]

I am new to Junit. I have a class with four methods. I am creating a test class with test cases. Can I have a test case that uses more than one methods of testing class or there should one test case ...
0
votes
2answers
225 views

Handling repetitive unit testing tasks [duplicate]

This problem arose whilst writing a simple 3D vector class. The class contained methods (Java, so no operator overloading) for addition, subtraction, multiplication, and division. These methods ...
1
vote
0answers
49 views

How many tests cases should there be for a method? [duplicate]

Unit testing has been widely lauded as an indispensable part of software development, and TDD has many proponents. However, due to the combinatorial nature of various pieces of code, it can be ...
29
votes
4answers
2k views

Unit testing best practices for a unit testing newbie

In recent years, I have only written small components for people in larger projects or small tools. I have never written a unit test and it always seems like learning how to write them and actually ...
12
votes
3answers
984 views

Unit Testing Competition

My employers runs a monthly unit testing day competition. One entire day is dedicated to writing unit tests -- obviously we do more testing throughout the month, but this is an entire day -- and the "...
2
votes
2answers
508 views

Unit testing and reality [closed]

I m actually studying Unit testing, reading some articles on the internet and trying to understand how it works exactly, but it's not very clear for me actually. What should I test ? I have seen ...
6
votes
3answers
614 views

Do people use unit testing to formalize assumptions in code?

One of the things I struggle with when unit testing is deciding what behaviors to actually test. I think part of my struggle stems from how most unit testing tutorials don't use good examples of ...
3
votes
3answers
203 views

Do tests that asserts a user can't do an action have any value?

Given a system with static permissions (1 permission for every action that can be made: create a resource, update a resource, etc), and dynamic roles (can be created and assign permissions to it ...
5
votes
2answers
335 views

Unit tests tactics

The only unit tests tactic I'm familiar with is comparing against golden data _ a predefined set of input data for which output is known (preferably including corner cases). I cannot think of any ...
6
votes
2answers
409 views

Is it ok to write “extra” unit tests?

My understanding of how TDD should work is that you write a failing test for the next bit of functionality you want to add to a function or object, code until the test passes and then write the next ...
1
vote
4answers
903 views

Looping Exhaustive Test Cases - A Good Practice?

Sometimes we have code like this: private static final List<Goat> INEDIBLE_GOATS = [GOAT_A, GOAT_B, GOAT_C] void eatGoat(Goat goat) { if(INEDIBLE_GOATS.contains(goat)) { throw new ...
1
vote
0answers
44 views

Unit testing multiple values [duplicate]

If I create a function to calculate the square root of a number, I suppose i should write a single unit test (maybe two, to test how it handles negative numbers). But what if I have a function which ...