coder
coder

Reputation: 63

How many tests should I apply to test doubly Linked-list?

I have a doubly linked list int. I want to test Get() method:

public E get (int index)

how many tests should I implement in JUnit to Cover fully cases ?

Thank you and hope to have answer soon.

Upvotes: 2

Views: 773

Answers (3)

Timothy Truckle
Timothy Truckle

Reputation: 15622

Think of what behavior the list should have.

For each sentence you can build with the pattern:
given [data combination] as input the List should [expected behavior]
you should have a single test method.

When building this sentences you should consider valid input data as well as error conditions.

Upvotes: 0

Minh Bui
Minh Bui

Reputation: 1030

I think you can follow all tests below:

  1. Test Get(0)from an empty list.
  2. Test Get(-1) from a list with 01 element
  3. Test Get(0) from a list with 1 element
  4. Test Get(1) from a list with 2 element.

Upvotes: 4

Codor
Codor

Reputation: 17605

Although the question is a bit broad, I think the following cases could be implemented.

  1. accessing an empty list
  2. accessing the first element of a nonempty list
  3. accessing the last element of a nonempty list
  4. accessing an element other than the first and the last of a list with at least 3 entries
  5. accessing every element of a nonempty list

Upvotes: 2

Related Questions