Using JUnit from the command line on Ubuntu

I don't usually do Java very much, but I wanted to use JUnit a little, so I made a note of how to use it quickly.

While saying "on Ubuntu", the confirmation environment is "Ubuntu 16.04.3 LTS" of "Bash on Ubuntu on Windows", but I think that the real thing is okay.

  1. JUnit 3

1.1. Installation

sudo apt install junit

1.2. Compile

javac -cp ./:/usr/share/java/junit.jar TestClassName.java

It's really a good idea to add the jar to the environment variable CLASSPATH.

1.3. Execution

junit TestClassName

You can run it with java nachara, which is more convenient.

  1. JUnit 4

2.1. Installation

sudo apt install junit4

2.2. Compile

javac -cp ./:/usr/share/java/junit4.jar TestClassName.java

You don't have to give the jar a long version name.

2.3. Execution

java -cp ./:/usr/share/java/junit4.jar org.junit.runner.JUnitCore TestClassName

There seems to be no junit4 command for JUnit 4 a little disappointing ... If you want to make your own, can you do it right away?

3. Other references

-"JUnit4 memo (Hishidama's JUnit4 Memo)" --Differences between JUnit 3 and JUnit 4 etc.

Recommended Posts

Using JUnit from the command line on Ubuntu
Notes on updating Ubuntu from the command line (16.04 → 18.04, 18.04 → 20.04 both)
Instructions for installing and using the AWS command line (awscli) on CentOS
How to run a GIF file from the Linux command line (Ubuntu)
Tips for using the Spotify app on Ubuntu
Use your own docker-compose.yml on the command line
Compile and run Java on the command line
Using Flutter on Ubuntu (Part 2)
A memo of what I did from a blank state to searching for characters using the "grep command" on "Ubuntu"
How to apply C code format from the command line
I want to use Java Applet easily on the command line without using an IDE
Using Azure IOT Hub on Ubuntu 20.10.
Install ngrok on ubuntu16.04 using Vagrant
Build the latest Samba 4 on Ubuntu 20.04
Use the iostat command on CentOS 8
Installing and using Ansible on Ubuntu 16.04
How to run a Kotlin Coroutine sample from the command line
Install lsb_release from the command line when lsb_release fails in docker environment
How to make Ubuntu a fixed IP address on the command line (explained as carefully as possible)
How to place geckodriver (Selenium WebDriver) on the path using Maven command
Try using the service on Android Oreo
Kick ShellScript on the server from Java
Install OpenJDK (Java) on the latest Ubuntu
How to change the timezone on Ubuntu
Try using the Emotion API from Android
Using templates on the classpath with Apache Velocity
I tried using Junit on Mac VScode Maven
Migration from Eclipse to IntelliJ (on the way)
Display the System Monitor applet on the Ubuntu 20.04 taskbar
Android application development using Unity + ARCore on Ubuntu
A fledgling engineer learned JUnit from the basics
Try accessing the dataset from Java using JZOS
Install the latest version of Jenkins on Ubuntu 16
JDBC operation check from xampp installation on Ubuntu
Solved the problem that the test could not be executed from the command line with spring-boot-starter-test
tmux on Ubuntu
[Ubuntu 20.04] Display the day of the week on the date / clock
Output the maximum value from the array using Java standard output
I built an Ubuntu environment on Windows 10 using WSL2.
Setting up the FreeBSD desktop environment on Ubuntu + qemu
Install the latest hardware drivers from ELRepo on CentOS
Run the Android emulator on Docker using Android Emulator Container Scripts
I tried using YOLO v4 on Ubuntu and ROS
Using the database (SQL Server 2014) from a Java program 2018/01/04
(Ruby on Rails6) Reflecting the posted content from the form
Install ag (the silver searcher) [on CentOS / Ubuntu / Mac]
The story of making Dr. Oakid using LINE BOT
Command to try using Docker for the time being
Try using the query attribute of Ruby on Rails
[Joke] What to do when the invalid sample rate is reached when using Mixxx on Ubuntu 20.04