[英]Testing a method to return unique values from a result set of a db query
Let's say there is a database table named "Students". 假设有一个名为“ Students”的数据库表。
Students Table
|---------------|---------------|
| Name | Age |
|---------------|---------------|
| John | 9 |
|---------------|---------------|
| Jane | 7 |
|---------------|---------------|
| Dana | 8 |
|---------------|---------------|
| John | 6 |
|---------------|---------------|
I make a request to the database to return all names using: 我使用以下命令向数据库返回所有名称:
SELECT Name FROM Students
So the result set would be: 因此结果集将是:
ResultSet rs = {"John" "Jane" "Dana" "John"}
I then want to return all unique values so I write a method called populateSet()
to populate a HashSet setOfNames
with rs
. 然后,我想返回所有唯一值,因此我编写了一个名为
populateSet()
的方法,以用rs
填充HashSet setOfNames
。
After executing populateSet(ResultSet rs)
, only unique names appear: 执行
populateSet(ResultSet rs)
,仅出现唯一的名称:
"John" "Jane" "Dana"
Here is the validation test: 这是验证测试:
public void testValidation() {
// Skipping the test data / db connection / query part
ResultSet rs = ResultSet received back from DB
Set<String> expected = {"John", "Jane", "Dana"};
Set<String> actual = WhateverClass.populateSet(rs);
assertEquals(expected, actual);
}
What are some of the possible unit tests that I could write? 我可以编写哪些可能的单元测试?
I know I should write a null, empty, and negative tests. 我知道我应该写一个空,空和否定的测试。 What are some corner cases?
什么是极端情况?
Potential corner cases: 潜在的极端情况:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.