Describe Your Tests

 class​ OxygenTankTest {
 static​ ​final​ ​double​ PERMILLE = 0.001;
 
  @Test
» @Disabled
 void​ testFill() {
  OxygenTank smallTank = OxygenTank.withCapacity(50);
 
  smallTank.fill(22);
 
  Assertions.assertEquals(0.44, smallTank.getStatus(), PERMILLE);
  }
 
» @Test
 private​ ​void​ testFill2() {
  OxygenTank bigTank = OxygenTank.withCapacity(10_000);
  bigTank.fill(5344.0);
 
  Executable when = () -> bigTank.fill(6000);
 
  Assertions.assertThrows(IllegalArgumentException.class, when);
  }
 }

Eventually, tests will fail. That’s what they’re there for—telling you when you break something. When tests fail, the first thing you’ll see is their name. Good names are valuable—they help you find the cause for failure faster. ...

Get Java By Comparison now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.