おそらくfriendListは、メソッドが定義されたクラスのフィールドです。テストにそう
:
- クラスのインスタンスを作成し、一致している必要があります文字列とfriendList
- コールremoveFriendを取り込みます。
- friendListに友人が含まれていないと主張します。
おそらく、リストにない友人のStringを渡して、リストが変更されていないことを確認することもできます。
編集:あなたがコメントで提起した興味深い質問。私は通常、物事のこれらの種類と非常に明示していますので、私は、私はいくつかのものを残しているが、それは一般的な概要である
List<String> friendList = new ArrayList<String>();
friendList.add("friend1");
friendList.add("friend2");
// assert before actually calling the method under test to make sure my setup is ok
assertEquals(2, friendList.size());
// theObj is an instance of the class you are testing
theObj.friendList = friendList;
// call the method under test
theObj.removeFriend("friend1");
// be explicit, the list should now have size1 and NOT contain the removed friend
assertEquals(1, friendList.size());
assertFalse(friendList.contains("friend1");
注意をするでしょう。リストにない文字列を削除する場合をテストできることを忘れないでください。また、同じ友人が2回リストに入っているケースをテストすることもできます。
友達を削除しますか?クラスの残りの部分はどのように見えるのですか? – OrangeDog