[JAVA] A fledgling engineer learned JUnit from the basics

A fledgling engineer is steadily as part of self-study ... For your information.

What is JUnit

Framework for Java unit testing (unit testing)

What is a unit test in the first place?

Tests to validate programs for classes and methods

Unit test type

White box test

--Design a test case that can confirm whether branching etc. is functioning correctly, considering the internal logic of the target function or method. --Often the programmers who understand the code itself do the testing themselves.

Black box test

--Design test cases only from external specifications without considering internal logic ――It is necessary to be able to judge whether the program meets the requirements rather than understanding the code itself.

There are two types of techniques for black-box testing:

Equivalence division method

A test technique in which values that produce similar results are grouped together and test data is selected from each group.

Boundary value analysis

A test technique that focuses on values that produce different results and selects test data near the boundary values.

Test class and test method

The test class name is generally "class name to be tested + Test"

//Tested class(Target.java)
public class Target {
//Test class(TargetTest.java)
public class TargetTest {

Test method notation


public void Test() throws Exception {
//Validation of the class or method to be tested

--Public method -Give @ org.junit.Test --The return value is void and has no arguments.

Comparative verification

The mechanism for verifying whether or not the measured value (actual value) and the expected value (expected value) match is called ** assertion **.

//Test code
String expected = "xxx";
String actual = yyy.zzz();
assertThat(actual, is(expected));

(Reference) https://books.rakuten.co.jp/rb/12058050/

Recommended Posts

A fledgling engineer learned JUnit from the basics
[Challenge CircleCI from 0] Learn the basics of CircleCI
[Ruby] From the basics to the inject method
Find the difference from a multiple of 10
Learn while making a WEB server Introduction to WEB application development from the basics
Using JUnit from the command line on Ubuntu
What an inexperienced engineer who took a leave of absence from college learned in 2020
3. Create a database to access from the web module
Using the database (SQL Server 2014) from a Java program 2018/01/04
Extract a specific element from the list of objects
21 Load the script from a file and execute it
I learned about the existence of a gemspec file
A record of studying the Spring Framework from scratch