How I Learned To Stop Writing Brittle Tests and Love Expressive APIs
Google Testing Blog
by Google Testing Bloggers
3d ago
This article was adapted from a Google Testing on the Toilet (TotT) episode. You can download a printer-friendly version of this TotT episode and post it in your office. By Titus Winters A valuable but challenging property for tests is “resilience,” meaning a test should only fail when something important has gone wrong. However, an opposite property may be easier to see: A “brittle” test is one that fails not for real problems that would break in production, but because the test itself is fragile for innocuous reasons. Error messages, changing the order of metadata headers in a web request ..read more
Visit website
Prefer Narrow Assertions in Unit Tests
Google Testing Blog
by Google Testing Bloggers
3w ago
This article was adapted from a Google Testing on the Toilet (TotT) episode. You can download a printer-friendly version of this TotT episode and post it in your office. by Kai Kent Your project is adding a loyalty promotion feature, so you add a new column CREATION_DATE to the ACCOUNT table. Suddenly the test below starts failing. Can you spot the problem? TEST_F(AccountTest, UpdatesBalanceAfterWithdrawal) {   ASSERT_OK_AND_ASSIGN(Account account,                      &nb ..read more
Visit website
What’s in a Name?
Google Testing Blog
by Google Testing Bloggers
3w ago
This is another post in our Code Health series. A version of this post originally appeared in Google bathrooms worldwide as a Google Testing on the Toilet episode. You can download a printer-friendly version to display in your office. by Adam Raider “There are only two hard things in computer science: cache invalidation and naming things.” —Phil Karlton Have you ever read an identifier only to realize later it doesn’t do what you expected? Or had to read the implementation in order to understand an interface? These indirections eat up our cognitive bandwidth and make our work more difficul ..read more
Visit website
Increase Test Fidelity By Avoiding Mocks
Google Testing Blog
by Google Testing Bloggers
2M ago
This article was adapted from a Google Testing on the Toilet (TotT) episode. You can download a printer-friendly version of this TotT episode and post it in your office. by Andrew Trenk and Dillon Bly Replacing your code’s dependencies with mocks can make unit tests easier to write and faster to run. However, among other problems, using mocks can lead to tests that are less effective at catching bugs. The fidelity of a test refers to how closely the behavior of the test resembles the behavior of the production code. A test with higher fidelity gives you higher confidence that your code will w ..read more
Visit website
Exceptional Exception Handling
Google Testing Blog
by Google Testing Bloggers
5M ago
This is another post in our Code Health series. A version of this post originally appeared in Google bathrooms worldwide as a Google Testing on the Toilet episode. You can download a printer-friendly version to display in your office. by Yiming Sun Have you ever seen huge exception-handling blocks? Here is an example. Let's assume we are calling bakePizza() to bake a pizza, and it can be overbaked, throwing a PizzaOverbakedException. class PizzaOverbakedException extends Exception {}; void bakePizza () throws PizzaOverbakedException {}; try {   // 100+ lines of code to prep ..read more
Visit website
Write Clean Code to Reduce Cognitive Load
Google Testing Blog
by Google Testing Bloggers
6M ago
This is another post in our Code Health series. A version of this post originally appeared in Google bathrooms worldwide as a Google Testing on the Toilet episode. You can download a printer-friendly version to display in your office. By Andrew Trenk Do you ever read code and find it hard to understand? You may be experiencing cognitive load! Cognitive load refers to the amount of mental effort required to complete a task. When reading code, you have to keep in mind information such as values of variables, conditional logic, loop indices, data structure state, and interface contracts. Cogni ..read more
Visit website
Include Only Relevant Details In Tests
Google Testing Blog
by Google Testing Bloggers
6M ago
This article was adapted from a Google Testing on the Toilet (TotT) episode. You can download a printer-friendly version of this TotT episode and post it in your office. By Dagang Wei What problem in the code below makes the test hard to follow? def test_get_balance(self):   settings = BankSettings(FDIC_INSURED, REGULATED, US_BASED)   account = Account(settings, ID, BALANCE, ADDRESS, NAME, EMAIL, PHONE)   self.assertEqual(account.GetBalance(), BALANCE) The problem is that there is a lot of noise in the account creation code, which makes it hard to ..read more
Visit website
Simplify Your Control Flows
Google Testing Blog
by Google Testing Bloggers
6M ago
This is another post in our Code Health series. A version of this post originally appeared in Google bathrooms worldwide as a Google Testing on the Toilet episode. You can download a printer-friendly version to display in your office. By Jeff Hoy When adding loops and conditionals, even simple code can become difficult to understand. Consider this change: if (commode.HasPreferredCustomer()) { if (commode.HasPreferredCustomer()) {   commode.WarmSeat();   commode.WarmSeat(); } else if (commode.CustomerOnPhone()) {   commode.ChillSeat(); } } Wh ..read more
Visit website
Shell Scripts: Stay Small & Simple
Google Testing Blog
by Google Testing Bloggers
7M ago
A version of this post originally appeared in Google bathrooms worldwide as a Google Testing on the Toilet episode. You can download a printer-friendly version to display in your office. By David Mandelberg Shell scripts (including Bash scripts) can be convenient for automating simple command line procedures, and they are often better than keeping complicated commands in a single developer's history. However, shell scripts can be hard to understand and maintain, and are typically not as well-supported as other programming languages. Shell scripts have less support for unit testing, and ther ..read more
Visit website
The Secret to Great Code Reviews: Respect Reviewers' Comments
Google Testing Blog
by Google Testing Bloggers
7M ago
This is another post in our Code Health series. A version of this post originally appeared in Google bathrooms worldwide as a Google Testing on the Toilet episode. You can download a printer-friendly version to display in your office. By Marius Latinis You prepared a code change and asked for a review. A reviewer left a comment you disagree with. Are you going to reply that you will not address the comment?  When addressing comments for your code reviewed by colleagues, find a solution that makes both you and the reviewer happy. The fact that a reviewer left a comment suggests you may ..read more
Visit website

Follow Google Testing Blog on FeedSpot

Continue with Google
Continue with Apple
OR