How to Install JUnit on Ubuntu 20.04 in 4 Practical Steps


In this article, we will see how to install Junit on Ubuntu 20.04 in 4 Simple Steps. JUnit is an open source unit testing framework for Java Based Projects. It was originally created by Erich Gamma and Kent Beck. JUnit provides capability to write and run your own test codes. JUnit is compatible on multiple platforms which makes it the most widely used Test framework. More on JUnit.

What is Unit Testing

Unit testing is basically a testing of small logic or code to verify that the output of the code is as expected based on the condition and data given on the Input.

Salient Features of JUnit

  • JUnit has very rich annotations set to identify the test methods.
  • It provides assertions for testing expected results.
  • JUnit has test runners capability for running tests.
  • It allow us to write quality codes which can make the test results faster.
  • JUnit tests cases are relatively simple to write as compared to other Unit Testing frameworks.
  • JUnit tests can be run automatically and provides its own feedback.
  • JUnit tests can be organized into test suites containing test cases.
  • JUnit can show the Test Progress Bar which changes its color based on results. If it runs successful then it turns green and if test fails then it turns to red.

How to Install JUnit on Ubuntu 20.04 in 4 Simple Steps

How to Install JUnit on Ubuntu 20.04 

Also Read: Easy Steps to Install Apache Nifi on Ubuntu 20.04

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 Server.

b) You should have apt or apt-get utility installed in Your Server.

c) You should have sudo or root access to run privileged commands.

Step 2: Update Your Server

If you want to update all your installed packages, then you can simply do that by running apt-get update command as shown below.

root@localhost:~# apt-get update
Hit:1 focal InRelease
Get:2 focal-updates InRelease [114 kB]
Get:3 focal-backports InRelease [101 kB]
Get:4 focal-security InRelease [109 kB]
Get:5 focal-updates/main amd64 Packages [983 kB]
Get:6 focal-updates/main i386 Packages [474 kB]
Get:7 focal-updates/main amd64 DEP-11 Metadata [263 kB]
Get:8 focal-updates/universe i386 Packages [572 kB]
Get:9 focal-updates/universe amd64 Packages [774 kB]
Get:10 focal-updates/universe amd64 DEP-11 Metadata [323 kB]
Get:11 focal-updates/universe DEP-11 64x64 Icons [358 kB]
Get:12 focal-updates/multiverse amd64 DEP-11 Metadata [2,468 B]
Get:13 focal-backports/universe amd64 DEP-11 Metadata [1,768 B]
Get:14 focal-security/main amd64 DEP-11 Metadata [24.4 kB]
Get:15 focal-security/universe amd64 DEP-11 Metadata [58.3 kB]
Fetched 4,158 kB in 3s (1,317 kB/s)
Reading package lists... Done


Step 3: Install JUnit

You can either use apt or apt-get to install JUnit package from Ubuntu Repository. Here we are using apt-get install junit command to install this package as shown below.

root@localhost:~# apt-get install junit
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 172 not upgraded.
Need to get 108 kB of archives.
After this operation, 159 kB of additional disk space will be used.
Get:1 focal/universe amd64 junit all 3.8.2-9 [108 kB]
Fetched 108 kB in 1s (168 kB/s)
Selecting previously unselected package junit.
(Reading database ... 186911 files and directories currently installed.)
Preparing to unpack .../archives/junit_3.8.2-9_all.deb ...
Unpacking junit (3.8.2-9) ...
Setting up junit (3.8.2-9) ...
Processing triggers for man-db (2.9.1-1) ...


Step 4: Uninstall JUnit

Once you are done with JUnit, you can remove the package by using apt-get remove junit command as shown below.

root@localhost:~# apt-get remove junit
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-5.8.0-41-generic linux-hwe-5.8-headers-5.8.0-41 linux-image-5.8.0-41-generic linux-modules-5.8.0-41-generic
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
0 upgraded, 0 newly installed, 1 to remove and 111 not upgraded.
After this operation, 159 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 224582 files and directories currently installed.)
Removing junit (3.8.2-9) ...
Processing triggers for man-db (2.9.1-1) ...

Leave a Comment