小工具知识网

当前位置: 首页 > 行业知识 > java unit test (junit)

行业知识

java unit test (junit)

2026-11-27 01:23:00 来源:互联网转载

demo

  1. compare
puindex.php/tags-41973.html" >blic int compare(int n1, int n2) {    if (n1 > n2) return 1;    else if (n1  
@Test@DisplayName("First number is less than the second")public void compare() {    Basics basicTests = new Basics();    int value = basicTests.compare(2, 3);    Assertions.assertEquals(-1, value);}
  1. sort array
public void sortArray(int[] array) {    int n = array.length;    for (int i = 0; i  array[j+1]) {                int temp = array[j];                array[j] = array[j+1];                array[j+1] = temp;            }        }    }}
@Test@DisplayName("Array sorted")public void sortArray() {    Basics basicTests = new Basics();    int[] array = {5, 8, 3, 9, 1, 6};    basicTests.sortArray(array);    Assertions.assertArrayEquals(new int[]{1, 3, 5, 6, 8, 9}, array);}
()()

上一篇:腾讯客户怎么取消服务器?

下一篇:如何选择消防服务器?