This is (again) a question of methodology...
Suppose we are testing a service that returns Article
s given id
s, i.e. List<Article> getArticles(List<Integer> ids);
. In addition, the corresponding location will be null
if the id is invalid.
Firstly fill the database by the SQL:
INSERT INTO articles VALUES (2001, "aaa"), (2002, "bbbb"), (2003, "cc"), (2004, "ddddd");
Then test by the following. Which way shall I do it (see details in the comments below)?
void testGetArticle() {
// NOTE: WHICH WAY?
// way1: one existing id, one nonexisting id.
var ids = Arrays.newArrayList(2002, 9999);
// way2: many existing ids, many nonexisting ids.
var ids = Arrays.newArrayList(1000, 1001, 2002, 2003, 2004, 9997, 9998, 9999);
List<Article> a = xx.getArticle(ids);
assertNull(a.get(0)); assertEquals(a.get(1), ...); ...etc... // assert each of the results
}
Thanks for any suggestions!