Logo Hiroshi Ukai's blog
Logo Inverted Logo
  • Posts
Hero Image
About Assertions 6

When testing, it is a situation that happens frequently, where you need to verify two values in a single test method. If those two values are irrelevant to each other, you should define two independent methods for them. However, in case we want to verify a certain relationship between them is satisfied or not, you can’t do so. Multi-values Assertion in Hamcrest public class Example { @Test public void example() { String firstName = composeFirstName(); String fullName = composeFullName(); assertThat(firstName, isNotNull()); assertThat(fullName, allOf( isNotNull(), containsString(firstName))); } } This is an example method for Hamcrest.

June 25, 2022 Read
Hero Image
About Assertions 5

Google Truth and AssertJ delivered a new style of assertions, where you don’t need to remember a lot of method names and class names placed in packages of Hamcrest’s jar file. It made possible to rely on your IDE for listing available methods, from which you can choose a desired one, instead of relying on your memory for it. The only thing that you need to remember is the fact that the method assertThat is what you need.

June 16, 2022 Read
Hero Image
About Assertions−4

Hamcrest gave us a good failure report and a readable test code style. But, the latter was relying on a Java’s language feature introduced in version 5.0, "static import". If we don’t use it, the code will look like the following. Hamcrest Without "static import" public class MultiConditions { @Test public void allOfMultiConditions() { String firstName = "Gaius"; String lastName = "Caesar"; String helloMessage = composeHelloMessageInEnglish(firstName, lastName); AllOf.assertThat(helloMessage, AllOf.

June 11, 2022 Read
Hero Image
About Assertions−3

I mentioned a situation, where we need to repeat fix, run, fix run…​ steps. It happens when we want to make sure multiple conditions are satisfied at the same time in a single test run. public class MultiConditions { @Test public void multiConditions() { String firstName = "Gaius"; String lastName = "Caesar"; String helloMessage = composeHelloMessageInEnglish(firstName, lastName); assertThat(helloMessage, containsString("Hello")); assertThat(helloMessage, containsString("Gaius")); assertThat(helloMessage, containsString("CAESAR")); } } Let’s suppose that we introduced bugs in the method composeHelloMessageInEnglish(String,String), where we inserted "Howdy", instead of "Hello" and at the same time, we forgot making family name all upper cases despite its specification of the function.

June 3, 2022 Read
Hero Image
About Assertions 2

Then the "Hamcrest" comes. It was the first and only library bundled with the JUnit (not anymore with JUnit5). As we saw in the previous post, the assertion capability was a part of the testing framework library until JUnit 3’s age. From the age of the book "Refactoring", how to describe a failure was a concern, only checking if a condition true or not wasn’t sufficient from the beginning. "How" it was not satisfied matters.

May 31, 2022 Read
Hero Image
About Assertions 1

When I write a test with JUnit, etc., I always feel annoyed at not being able to make it clean or doing so is really difficult. Let me state here, my principles in coding. "Repetitive things are machine’s, not human’s" "Tests are also codes. They should be as clean as the product" Perhaps, I need to add some other new principles to them later as my thought develops through posting entries to this blog, but anyway, I am going to call the set of my ideas that I am presenting here, "Test Design as Code".

May 31, 2022 Read
Hero Image
Second Post

Then trying ditaa, which wouldn’t be working with hugo. +-----+ |hello| +-----+

May 17, 2022 Read
Hero Image
First Post

This is my first post on this my new blog. Let me try the asciidoctor’s source feature. public class Hello { public static void main(String... args) { System.out.println("Hello, world"); } }

May 17, 2022 Read
Navigation
  • About
  • Projects
  • Recent Posts
Contact me:
  • dakusui
  • Twitter: @______HU

Stay up to date with email notification


By entering your email address, you agree to receive the newsletter of this website.

Liability Notice: This theme is under MIT license. So, you can use it for non-commercial, commercial, or private uses. You can modify or distribute the theme without requiring any permission from the theme author. However, the theme author does not provide any warranty or takes any liability for any issue with the theme.


Toha Theme Logo Toha
© 2022 Copyright.
Powered by Hugo Logo