单元测试,数组排序 [英] Unit testing-Sort Array

查看:134
本文介绍了单元测试,数组排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有排序号码的升序排列阵列的方法,我想测试这种方法。我创建了两个单元测试,一个通过所有元素循环,并声称,当前元素是小于一来之后,并且声称,排序后的数组具有相同的元件另一排序后的数组创建自己的另一种方法。

I have a method that sorts an array of numbers in ascending order and I want to test this method. I created two unit tests, one that loops through all the elements and asserts that the current element is less than the one coming after, and another method that asserts that the sorted array has the same elements as another sorted array I create myself.

是否有任何其他的方式来测试这个方法或这两个是罚款?

Is there any other way to test this method or those two are fine?

我使用Java

推荐答案

我还要补充测试,以覆盖所需的行为时:

I would also add tests to cover the desired behaviour when:


  • 输入数组为空

  • 输入数组为空或有一个单一的元素

不过,除非你有一个很好的理由,你或许应该使用内置的 Arrays.sort()而不是实现自己的排序。

However, unless you have a good reason, you should probably be using the built-in Arrays.sort() rather than implementing your own sort.

这篇关于单元测试,数组排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆