def setUp(self): self.users = [User('alice'), User('bob')] # This field can be reused across tests. self.forum = Forum() def testCanRegisterMultipleUsers(self): self._RegisterAllUsers() for user in self.users: # Use a for-loop to verify that all users are registered. self.assertTrue(self.forum.HasRegisteredUser(user)) def _RegisterAllUsers(self): # This method can be reused across tests. for user in self.users: self.forum.Register(user)
def setUp(self): self.forum = Forum() def testCanRegisterMultipleUsers(self): # Create the users in the test instead of relying on users created in setUp. user1 = User('alice') user2 = User('bob') # Register the users in the test instead of in a helper method, and don't use a for-loop. self.forum.Register(user1) self.forum.Register(user2) # Assert each user individually instead of using a for-loop. self.assertTrue(self.forum.HasRegisteredUser(user1)) self.assertTrue(self.forum.HasRegisteredUser(user2))
Author Don’t: I prefer short names so I’d rather
not change this. Unless you make
me? :)
Author Do: Best practice suggests omitting
obvious/generic terms. I’m not
sure how to reconcile that
advice with this request.
Reviewer Don’t: Why are you using this approach?
You’re adding unnecessary
complexity.
Reviewer Do: This concurrency model appears to
be adding complexity to the
system without any visible
performance benefit.
Reviewer Don’t: I don’t understand this.
Reviewer Do: If this is an optimization, can you
please add comments?
Author Don’t: That makes sense in some cases but
not here.
Author Do: I added a comment about why
it’s implemented that way.
assertEquals("Message has been sent", getString(notification, EXTRA_BIG_TEXT)); assertTrue( getString(notification, EXTRA_TEXT) .contains("Kurt Kluever <kak@google.com>"));
assertThat(getString(notification, EXTRA_BIG_TEXT)) .isEqualTo("Message has been sent"); assertThat(getString(notification, EXTRA_TEXT)) .contains("Kurt Kluever <kak@google.com>");
java.lang.AssertionError: Expecting: <[year: 2019 month: 7 day: 15 ]> to contain exactly in any order: <[year: 2019 month: 6 day: 30 ]> elements not found: <[year: 2019 month: 6 day: 30 ]> and elements not expected: <[year: 2019 month: 7 day: 15 ]>
value of: iterable.onlyElement() expected: year: 2019 month: 6 day: 30 but was: year: 2019 month: 7 day: 15
assertThat(notification).extras().string(EXTRA_BIG_TEXT) .isEqualTo("Message has been sent"); assertThat(notification).extras().string(EXTRA_TEXT) .contains("Kurt Kluever <kak@google.com>");