lundi 3 août 2015

Extent of the "expected" in Junit assertion tests

is there any guideline for how extensive the expected has to be? Let's assume I have the following constructor for a simple card deck.

public class deck {

public card[] deckCards = new card[52];

public deck() {

    int i = 0;

    for(int suit = 0; suit<4; suit++) {
        for(int rank=0; rank<13; rank++) {
            this.deckCards[i] = new card(rank,suit);
            i = i+1;
        }
    }
}}

Now, if I want to do a Junit-Test, then I'm probably going to use assertArrayEquals(), which means that I need to create the "expected array" first. In my case this would be 52 cards (4 suits times 13 ranks). Now, this would be quite tedious to write down. How am I supposed to test such long arrays (what if it's even longer)?

On a gut level I would test

  1. if the array has 52 non-null values.
  2. test the border cases, which means "A heart & 2 heart", "A clubs & 2 clubs", "A diamond & 2 diamond", "A spade & 2 spade".

So, is it really tedious manual work, to write down the "expected", or are there any conventions on how we approach that?

Aucun commentaire:

Enregistrer un commentaire