What is Java Assertion? Summary.

Overview

I did a Java Integration Test, so I'll output it so I don't forget it.

table of contents

  1. What is a Java assert statement?
  2. Assert Class methods, JUnit description

1. What is a Java assert statement?

What is a Java assert statement?

According to the official Oracle documentation

Assertions are statements in the Java programming language that allow you to test assumptions about a program.

Assertion life cycle

Assertions are ** always Boolean type **, and we will test on the assumption ** true **. If false, throw ** AssertionError **.

coverage

In addition, the degree to which the function is covered by the test is called ** coverage **. The higher the quality of ** coverage **, the less bugs.

2. Assert Class methods, JUnit description

assertEqual() Determine if the expected and actual results are the same

EqualIntegrationTest.java


/**
 * expected:Expected value
 * actual:Actual value
 * message:message(Displayed when the expected value and the actual value do not match)
 */ 
Assert.assertEqual(expected, actual);
Assert.assertEqual(message, expected, actual);

assertTrue() Determine if the given conditions are correct

TrueIntegrationTest.java


/**
 * actual:Actual value
 * message:message(Display if the given conditions are incorrect)
 */ 
Assert.assertTrue(expected > 1);
Assert.assertTrue(message, expected > 1);

assertNotNull() Determine if the given Object is not null

NotNullIntegrationTest.java


/**
 * object:Expected value
 * message:message(Displayed when object is null)
 */
Assert.assertNotNull(object);
Assert.assertNotNull(message, object);

assertNull() Determine if the given Object is null

NullIntegrationTest.java


/**
 * object:Expected value
 * message:message(Show if object is not null)
 */ 
Assert.assertNull(object);
Assert.assertNull(message, object);

assertSame() Determine if two given Objects refer to the same Object

SameIntegrationTest.java


/**
 * expectedObject:Expected value
 * actualObject:Actual value
 * message:message(Show if object is not null)
 */ 
Assert.assertSame(expectedObject, actualObject);
Assert.assertSame(message, expectedObject, actualObject);

assertThat()  It's basically a comparison, but its usage is wide-ranging Details

Reference material

Recommended Posts

What is Java Assertion? Summary.
What is java
What is Java <>?
What is Java
What is Java Encapsulation?
What is Java technology?
What is Java API-java
[Java] What is flatMap?
[Java] What is JavaBeans?
[Java] What is ArrayList?
What is a Java collection?
[Java] What is jaee j2ee?
[Java] What is class inheritance?
[Java basics] What is Class?
What is java escape analysis?
What is JVM (Java Virtual Machine)?
My RxSwift Summary ③ (What is Observable?)
What is thread safe (with Java)
[Java] What is Concurrent Modification Exception?
What is a lambda expression (Java)
My RxSwift Summary ⑤ (What is Subjects / Relay?)
What is Cubby
What is Docker?
What is a class in Java language (3 /?)
My RxSwift Summary ④ (What is dispose bag?)
Java knowledge summary
What is null? ]
Java Generics Summary
What is Keycloak
What is maven?
What is Jackson?
Java related summary
What is Docker
What is self
What is Jenkins
What is ArgumentMatcher?
What is IM-Juggling?
What is the best file reading (Java)
What is a class in Java language (1 /?)
What is params
What is SLF4J?
What is Java and Development Environment (MAC)
What is a class in Java language (2 /?)
What is Facade? ??
What is Gradle?
What is POJO
What is the main method in Java?
Java 8 documentation summary
What is centOS
What is RubyGem?
What is programming?
What is before_action?
What is Docker
Java 11 document summary
What is Byte?
What is Tomcat
What is the Java Servlet / JSP MVC model?
What is the volatile modifier for Java variables?
Java 12 new feature summary
What is Maven Assembly?
What is `docker-compose up`?