Is there a standard JUnit test framework? How many statements per test usually prefer?

I will explain this better with an example:

Imagine that I have a function that receives an array of integers X and an additional integer that contains the starting position, it calculates the average of 10 numbers in the array starting at this position, but ignores the values 0and returns -1000000if the array does not contain 10 or more values ​​from the starting position to the end:

public double calculateAverage(ArrayList<Integer>, int startingPosition){
    //functionLogic
    return myAverage;
}

I am new to unit testing, but I would suggest doing the following tests here:

  • Test a list of 20 integers and 5as a starting position. (should return an average of 10 numbers from 5to 14)
  • Test a list of 20 integers and 15as a starting position. (must return -1000000)
  • Test with 9 whole list. (must return -1000000, regardless of the starting position)
  • A test with an integer of 20, in which half of the numbers 0and 5 is the starting position. (should return the average number of numbers between 5and 14without 0s).
  • A test with an integer of 20, in which half of the numbers 0and 15 is the starting position. (must return -1000000)

These tests may be insufficient or too large or just bad tests, please feel free to comment on any improvements, as I am sure that most of you know more about unit tests than I do.

My question is:

5 JUnit? 1 5 ? () 2 3?

?

.

+4
2

, , "" - limit .

: .

: - ( ) . "" , , , .

, ( "", /).

: , javacodegeeks.

+4

, .
, .

.

+2

Source: https://habr.com/ru/post/1667233/


All Articles