Author Photo

Ahmer's SysAdmin Recipes is a blog for Linux System Administrators. This blog provides recipes for Installation & Configuration of Linux, Ubuntu, Oracle Database, MySQL, Apache, Nginx, Oracle Cloud Control, FreeIPA, Kerberos & OpenLDAP, Subversion, PXE, DevOps, etc. over Red Hat Enterprise Linux (RHEL), CentOS, Ubuntu and Windows.

Please give me your feedback and help me improve this blog. Please let me know If you want me to write on a specific topic.

Wednesday, 19 December 2018

JUnit: Integrate with Apache Ant on CentOS 7

Integrate-Junit-with-Apache-Ant-on-CentOS-7JUnit is an open source unit testing framework for Java programming language. JUnit plays a very important role in test-driven development. Junit is linked as a JAR at compile-time. The framework resides under package org.junit for Junit 4 or later. JUnit can be integrated with Apache Ant to create a deployment pipeline for Java applications.

In this article, we will install and Integrate Apache Ant with JUnit on CentOS 7.

 

System Specification:

We have a CentOS 7 virtual machine with following specification:

Operating System CentOS 7
Hostname junit-01.example.com
IP Address 192.168.116.131/24

 

Install Java Development Kit (JDK) on CentOS 7:

Connect to junit-01.example.com using ssh.

Install Java Development Kit (JDK) using yum command.

[root@junit-01 ~]# yum install -y java-1.8.0-openjdk ... --> Processing Dependency: libxcb.so.1()(64bit) for package: libX11-1.6.5-2.el7.x86_64 ---> Package libXcomposite.x86_64 0:0.4.4-4.1.el7 will be installed ---> Package libXext.x86_64 0:1.3.3-3.el7 will be installed ---> Package libXi.x86_64 0:1.7.9-1.el7 will be installed ---> Package libXrender.x86_64 0:0.9.10-1.el7 will be installed ---> Package libXtst.x86_64 0:1.2.3-1.el7 will be installed ---> Package libjpeg-turbo.x86_64 0:1.2.90-6.el7 will be installed ---> Package xorg-x11-fonts-Type1.noarch 0:7.5-9.el7 will be installed --> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.5-9.el7.noarch --> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.5-9.el7.noarch --> Processing Dependency: mkfontdir for package: xorg-x11-fonts-Type1-7.5-9.el7.noarch --> Processing Dependency: mkfontdir for package: xorg-x11-fonts-Type1-7.5-9.el7.noarch --> Running transaction check ---> Package copy-jdk-configs.noarch 0:3.3-10.el7_5 will be installed ---> Package dejavu-sans-fonts.noarch 0:2.33-6.el7 will be installed --> Processing Dependency: dejavu-fonts-common = 2.33-6.el7 for package: dejavu-sans-fonts-2.33-6.el7.noarch ---> Package fontpackages-filesystem.noarch 0:1.44-8.el7 will be installed ---> Package javapackages-tools.noarch 0:3.4.1-11.el7 will be installed --> Processing Dependency: python-javapackages = 3.4.1-11.el7 for package: javapackages-tools-3.4.1-11.el7.noarch ---> Package libICE.x86_64 0:1.0.9-9.el7 will be installed ---> Package libSM.x86_64 0:1.2.2-2.el7 will be installed ---> Package libX11-common.noarch 0:1.6.5-2.el7 will be installed ---> Package libxcb.x86_64 0:1.13-1.el7 will be installed --> Processing Dependency: libXau.so.6()(64bit) for package: libxcb-1.13-1.el7.x86_64 ---> Package lksctp-tools.x86_64 0:1.0.17-2.el7 will be installed ---> Package ttmkfdir.x86_64 0:3.0.9-42.el7 will be installed ---> Package tzdata-java.noarch 0:2018g-1.el7 will be installed ---> Package xorg-x11-font-utils.x86_64 1:7.5-21.el7 will be installed --> Processing Dependency: libfontenc.so.1()(64bit) for package: 1:xorg-x11-font-utils-7.5-21.el7.x86_64 --> Running transaction check ---> Package dejavu-fonts-common.noarch 0:2.33-6.el7 will be installed ---> Package libXau.x86_64 0:1.0.8-2.1.el7 will be installed ---> Package libfontenc.x86_64 0:1.1.3-3.el7 will be installed ---> Package python-javapackages.noarch 0:3.4.1-11.el7 will be installed --> Processing Dependency: python-lxml for package: python-javapackages-3.4.1-11.el7.noarch --> Running transaction check ---> Package python-lxml.x86_64 0:3.2.1-4.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: java-1.8.0-openjdk x86_64 1:1.8.0.191.b12-1.el7_6 updates 254 k Installing for dependencies: copy-jdk-configs noarch 3.3-10.el7_5 base 21 k dejavu-fonts-common noarch 2.33-6.el7 base 64 k dejavu-sans-fonts noarch 2.33-6.el7 base 1.4 M fontconfig x86_64 2.13.0-4.3.el7 base 254 k fontpackages-filesystem noarch 1.44-8.el7 base 9.9 k giflib x86_64 4.1.6-9.el7 base 40 k java-1.8.0-openjdk-headless x86_64 1:1.8.0.191.b12-1.el7_6 updates 32 M javapackages-tools noarch 3.4.1-11.el7 base 73 k libICE x86_64 1.0.9-9.el7 base 66 k libSM x86_64 1.2.2-2.el7 base 39 k libX11 x86_64 1.6.5-2.el7 base 606 k libX11-common noarch 1.6.5-2.el7 base 164 k libXau x86_64 1.0.8-2.1.el7 base 29 k libXcomposite x86_64 0.4.4-4.1.el7 base 22 k libXext x86_64 1.3.3-3.el7 base 39 k libXi x86_64 1.7.9-1.el7 base 40 k libXrender x86_64 0.9.10-1.el7 base 26 k libXtst x86_64 1.2.3-1.el7 base 20 k libfontenc x86_64 1.1.3-3.el7 base 31 k libjpeg-turbo x86_64 1.2.90-6.el7 base 134 k libxcb x86_64 1.13-1.el7 base 214 k lksctp-tools x86_64 1.0.17-2.el7 base 88 k python-javapackages noarch 3.4.1-11.el7 base 31 k python-lxml x86_64 3.2.1-4.el7 base 758 k ttmkfdir x86_64 3.0.9-42.el7 base 48 k tzdata-java noarch 2018g-1.el7 updates 185 k xorg-x11-font-utils x86_64 1:7.5-21.el7 base 104 k xorg-x11-fonts-Type1 noarch 7.5-9.el7 base 521 k Transaction Summary ================================================================================ Install 1 Package (+28 Dependent packages) Total download size: 37 M Installed size: 119 M Downloading packages: (1/29): copy-jdk-configs-3.3-10.el7_5.noarch.rpm | 21 kB 00:00 (2/29): dejavu-fonts-common-2.33-6.el7.noarch.rpm | 64 kB 00:01 (3/29): giflib-4.1.6-9.el7.x86_64.rpm | 40 kB 00:00 (4/29): fontpackages-filesystem-1.44-8.el7.noarch.rpm | 9.9 kB 00:01 (5/29): javapackages-tools-3.4.1-11.el7.noarch.rpm | 73 kB 00:01 (6/29): libICE-1.0.9-9.el7.x86_64.rpm | 66 kB 00:01 (7/29): libSM-1.2.2-2.el7.x86_64.rpm | 39 kB 00:00 (8/29): fontconfig-2.13.0-4.3.el7.x86_64.rpm | 254 kB 00:04 (9/29): dejavu-sans-fonts-2.33-6.el7.noarch.rpm | 1.4 MB 00:05 (10/29): java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64.r | 254 kB 00:04 (11/29): libXcomposite-0.4.4-4.1.el7.x86_64.rpm | 22 kB 00:00 (12/29): libXau-1.0.8-2.1.el7.x86_64.rpm | 29 kB 00:00 (13/29): libXi-1.7.9-1.el7.x86_64.rpm | 40 kB 00:01 (14/29): libX11-1.6.5-2.el7.x86_64.rpm | 606 kB 00:04 (15/29): libX11-common-1.6.5-2.el7.noarch.rpm | 164 kB 00:04 (16/29): libXtst-1.2.3-1.el7.x86_64.rpm | 20 kB 00:00 (17/29): libfontenc-1.1.3-3.el7.x86_64.rpm | 31 kB 00:00 (18/29): libXext-1.3.3-3.el7.x86_64.rpm | 39 kB 00:03 (19/29): libXrender-0.9.10-1.el7.x86_64.rpm | 26 kB 00:02 (20/29): libjpeg-turbo-1.2.90-6.el7.x86_64.rpm | 134 kB 00:01 (21/29): python-javapackages-3.4.1-11.el7.noarch.rpm | 31 kB 00:03 (22/29): libxcb-1.13-1.el7.x86_64.rpm | 214 kB 00:04 (23/29): python-lxml-3.2.1-4.el7.x86_64.rpm | 758 kB 00:06 (24/29): ttmkfdir-3.0.9-42.el7.x86_64.rpm | 48 kB 00:05 (25/29): xorg-x11-font-utils-7.5-21.el7.x86_64.rpm | 104 kB 00:01 (26/29): lksctp-tools-1.0.17-2.el7.x86_64.rpm | 88 kB 00:10 (27/29): tzdata-java-2018g-1.el7.noarch.rpm | 185 kB 00:06 (28/29): xorg-x11-fonts-Type1-7.5-9.el7.noarch.rpm | 521 kB 00:07 (29/29): java-1.8.0-openjdk-headless-1.8.0.191.b12-1.el7_6 | 32 MB 01:05 -------------------------------------------------------------------------------- Total 561 kB/s | 37 MB 01:07 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libjpeg-turbo-1.2.90-6.el7.x86_64 1/29 Installing : fontpackages-filesystem-1.44-8.el7.noarch 2/29 Installing : libICE-1.0.9-9.el7.x86_64 3/29 Installing : libSM-1.2.2-2.el7.x86_64 4/29 Installing : dejavu-fonts-common-2.33-6.el7.noarch 5/29 Installing : dejavu-sans-fonts-2.33-6.el7.noarch 6/29 Installing : fontconfig-2.13.0-4.3.el7.x86_64 7/29 Installing : libfontenc-1.1.3-3.el7.x86_64 8/29 Installing : 1:xorg-x11-font-utils-7.5-21.el7.x86_64 9/29 Installing : tzdata-java-2018g-1.el7.noarch 10/29 Installing : libX11-common-1.6.5-2.el7.noarch 11/29 Installing : libXau-1.0.8-2.1.el7.x86_64 12/29 Installing : libxcb-1.13-1.el7.x86_64 13/29 Installing : libX11-1.6.5-2.el7.x86_64 14/29 Installing : libXext-1.3.3-3.el7.x86_64 15/29 Installing : libXi-1.7.9-1.el7.x86_64 16/29 Installing : libXtst-1.2.3-1.el7.x86_64 17/29 Installing : giflib-4.1.6-9.el7.x86_64 18/29 Installing : libXrender-0.9.10-1.el7.x86_64 19/29 Installing : libXcomposite-0.4.4-4.1.el7.x86_64 20/29 Installing : lksctp-tools-1.0.17-2.el7.x86_64 21/29 Installing : copy-jdk-configs-3.3-10.el7_5.noarch 22/29 Installing : ttmkfdir-3.0.9-42.el7.x86_64 23/29 Installing : xorg-x11-fonts-Type1-7.5-9.el7.noarch 24/29 Installing : python-lxml-3.2.1-4.el7.x86_64 25/29 Installing : python-javapackages-3.4.1-11.el7.noarch 26/29 Installing : javapackages-tools-3.4.1-11.el7.noarch 27/29 Installing : 1:java-1.8.0-openjdk-headless-1.8.0.191.b12-1.el7_6.x86_ 28/29 Installing : 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64 29/29 Verifying : libXext-1.3.3-3.el7.x86_64 1/29 Verifying : libXi-1.7.9-1.el7.x86_64 2/29 Verifying : fontconfig-2.13.0-4.3.el7.x86_64 3/29 Verifying : giflib-4.1.6-9.el7.x86_64 4/29 Verifying : libXrender-0.9.10-1.el7.x86_64 5/29 Verifying : 1:xorg-x11-font-utils-7.5-21.el7.x86_64 6/29 Verifying : python-lxml-3.2.1-4.el7.x86_64 7/29 Verifying : libICE-1.0.9-9.el7.x86_64 8/29 Verifying : fontpackages-filesystem-1.44-8.el7.noarch 9/29 Verifying : ttmkfdir-3.0.9-42.el7.x86_64 10/29 Verifying : libjpeg-turbo-1.2.90-6.el7.x86_64 11/29 Verifying : copy-jdk-configs-3.3-10.el7_5.noarch 12/29 Verifying : python-javapackages-3.4.1-11.el7.noarch 13/29 Verifying : dejavu-fonts-common-2.33-6.el7.noarch 14/29 Verifying : libXcomposite-0.4.4-4.1.el7.x86_64 15/29 Verifying : libXtst-1.2.3-1.el7.x86_64 16/29 Verifying : libxcb-1.13-1.el7.x86_64 17/29 Verifying : lksctp-tools-1.0.17-2.el7.x86_64 18/29 Verifying : xorg-x11-fonts-Type1-7.5-9.el7.noarch 19/29 Verifying : libX11-1.6.5-2.el7.x86_64 20/29 Verifying : 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64 21/29 Verifying : dejavu-sans-fonts-2.33-6.el7.noarch 22/29 Verifying : javapackages-tools-3.4.1-11.el7.noarch 23/29 Verifying : 1:java-1.8.0-openjdk-headless-1.8.0.191.b12-1.el7_6.x86_ 24/29 Verifying : libXau-1.0.8-2.1.el7.x86_64 25/29 Verifying : libSM-1.2.2-2.el7.x86_64 26/29 Verifying : libX11-common-1.6.5-2.el7.noarch 27/29 Verifying : tzdata-java-2018g-1.el7.noarch 28/29 Verifying : libfontenc-1.1.3-3.el7.x86_64 29/29 Installed: java-1.8.0-openjdk.x86_64 1:1.8.0.191.b12-1.el7_6 Dependency Installed: copy-jdk-configs.noarch 0:3.3-10.el7_5 dejavu-fonts-common.noarch 0:2.33-6.el7 dejavu-sans-fonts.noarch 0:2.33-6.el7 fontconfig.x86_64 0:2.13.0-4.3.el7 fontpackages-filesystem.noarch 0:1.44-8.el7 giflib.x86_64 0:4.1.6-9.el7 java-1.8.0-openjdk-headless.x86_64 1:1.8.0.191.b12-1.el7_6 javapackages-tools.noarch 0:3.4.1-11.el7 libICE.x86_64 0:1.0.9-9.el7 libSM.x86_64 0:1.2.2-2.el7 libX11.x86_64 0:1.6.5-2.el7 libX11-common.noarch 0:1.6.5-2.el7 libXau.x86_64 0:1.0.8-2.1.el7 libXcomposite.x86_64 0:0.4.4-4.1.el7 libXext.x86_64 0:1.3.3-3.el7 libXi.x86_64 0:1.7.9-1.el7 libXrender.x86_64 0:0.9.10-1.el7 libXtst.x86_64 0:1.2.3-1.el7 libfontenc.x86_64 0:1.1.3-3.el7 libjpeg-turbo.x86_64 0:1.2.90-6.el7 libxcb.x86_64 0:1.13-1.el7 lksctp-tools.x86_64 0:1.0.17-2.el7 python-javapackages.noarch 0:3.4.1-11.el7 python-lxml.x86_64 0:3.2.1-4.el7 ttmkfdir.x86_64 0:3.0.9-42.el7 tzdata-java.noarch 0:2018g-1.el7 xorg-x11-font-utils.x86_64 1:7.5-21.el7 xorg-x11-fonts-Type1.noarch 0:7.5-9.el7 Complete!

 

Install Apache Ant on CentOS 7:

Install Apache Ant using yum command.

[root@junit-01 ~]# yum install -y ant Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: repo.inara.pk * extras: repo.inara.pk * updates: repo.inara.pk Resolving Dependencies --> Running transaction check ---> Package ant.noarch 0:1.9.4-2.el7 will be installed --> Processing Dependency: java-devel >= 1.5.0 for package: ant-1.9.4-2.el7.noarch --> Processing Dependency: xml-commons-apis for package: ant-1.9.4-2.el7.noarch --> Processing Dependency: xerces-j2 for package: ant-1.9.4-2.el7.noarch --> Processing Dependency: perl for package: ant-1.9.4-2.el7.noarch --> Running transaction check ---> Package java-1.8.0-openjdk-devel.x86_64 1:1.8.0.191.b12-1.el7_6 will be installed ---> Package perl.x86_64 4:5.16.3-293.el7 will be installed --> Processing Dependency: perl-libs = 4:5.16.3-293.el7 for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Socket) >= 1.3 for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Scalar::Util) >= 1.10 for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl-macros for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl-libs for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(threads::shared) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(threads) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(constant) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Time::Local) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Time::HiRes) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Storable) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Socket) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Scalar::Util) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Pod::Simple::XHTML) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Pod::Simple::Search) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Getopt::Long) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Filter::Util::Call) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(File::Temp) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(File::Spec::Unix) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(File::Spec::Functions) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(File::Spec) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(File::Path) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Exporter) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Cwd) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: perl(Carp) for package: 4:perl-5.16.3-293.el7.x86_64 --> Processing Dependency: libperl.so()(64bit) for package: 4:perl-5.16.3-293.el7.x86_64 ---> Package xerces-j2.noarch 0:2.11.0-17.el7_0 will be installed --> Processing Dependency: xml-commons-resolver >= 1.2 for package: xerces-j2-2.11.0-17.el7_0.noarch --> Processing Dependency: xalan-j2 >= 2.7.1 for package: xerces-j2-2.11.0-17.el7_0.noarch --> Processing Dependency: osgi(org.apache.xml.serializer) for package: xerces-j2-2.11.0-17.el7_0.noarch --> Processing Dependency: osgi(org.apache.xml.resolver) for package: xerces-j2-2.11.0-17.el7_0.noarch ---> Package xml-commons-apis.noarch 0:1.4.01-16.el7 will be installed --> Running transaction check ---> Package perl-Carp.noarch 0:1.26-244.el7 will be installed ---> Package perl-Exporter.noarch 0:5.68-3.el7 will be installed ---> Package perl-File-Path.noarch 0:2.09-2.el7 will be installed ---> Package perl-File-Temp.noarch 0:0.23.01-3.el7 will be installed ---> Package perl-Filter.x86_64 0:1.49-3.el7 will be installed ---> Package perl-Getopt-Long.noarch 0:2.40-3.el7 will be installed --> Processing Dependency: perl(Pod::Usage) >= 1.14 for package: perl-Getopt-Long-2.40-3.el7.noarch --> Processing Dependency: perl(Text::ParseWords) for package: perl-Getopt-Long-2.40-3.el7.noarch ---> Package perl-PathTools.x86_64 0:3.40-5.el7 will be installed ---> Package perl-Pod-Simple.noarch 1:3.28-4.el7 will be installed --> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.28-4.el7.noarch --> Processing Dependency: perl(Encode) for package: 1:perl-Pod-Simple-3.28-4.el7.noarch ---> Package perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 will be installed ---> Package perl-Socket.x86_64 0:2.010-4.el7 will be installed ---> Package perl-Storable.x86_64 0:2.45-3.el7 will be installed ---> Package perl-Time-HiRes.x86_64 4:1.9725-3.el7 will be installed ---> Package perl-Time-Local.noarch 0:1.2300-2.el7 will be installed ---> Package perl-constant.noarch 0:1.27-2.el7 will be installed ---> Package perl-libs.x86_64 4:5.16.3-293.el7 will be installed ---> Package perl-macros.x86_64 4:5.16.3-293.el7 will be installed ---> Package perl-threads.x86_64 0:1.87-4.el7 will be installed ---> Package perl-threads-shared.x86_64 0:1.43-6.el7 will be installed ---> Package xalan-j2.noarch 0:2.7.1-23.el7 will be installed ---> Package xml-commons-resolver.noarch 0:1.2-15.el7 will be installed --> Running transaction check ---> Package perl-Encode.x86_64 0:2.51-7.el7 will be installed ---> Package perl-Pod-Escapes.noarch 1:1.04-293.el7 will be installed ---> Package perl-Pod-Usage.noarch 0:1.63-3.el7 will be installed --> Processing Dependency: perl(Pod::Text) >= 3.15 for package: perl-Pod-Usage-1.63-3.el7.noarch --> Processing Dependency: perl-Pod-Perldoc for package: perl-Pod-Usage-1.63-3.el7.noarch ---> Package perl-Text-ParseWords.noarch 0:3.29-4.el7 will be installed --> Running transaction check ---> Package perl-Pod-Perldoc.noarch 0:3.20-4.el7 will be installed --> Processing Dependency: perl(parent) for package: perl-Pod-Perldoc-3.20-4.el7.noarch --> Processing Dependency: perl(HTTP::Tiny) for package: perl-Pod-Perldoc-3.20-4.el7.noarch ---> Package perl-podlators.noarch 0:2.5.1-3.el7 will be installed --> Running transaction check ---> Package perl-HTTP-Tiny.noarch 0:0.033-3.el7 will be installed ---> Package perl-parent.noarch 1:0.225-244.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: ant noarch 1.9.4-2.el7 base 2.0 M Installing for dependencies: java-1.8.0-openjdk-devel x86_64 1:1.8.0.191.b12-1.el7_6 updates 9.8 M perl x86_64 4:5.16.3-293.el7 base 8.0 M perl-Carp noarch 1.26-244.el7 base 19 k perl-Encode x86_64 2.51-7.el7 base 1.5 M perl-Exporter noarch 5.68-3.el7 base 28 k perl-File-Path noarch 2.09-2.el7 base 26 k perl-File-Temp noarch 0.23.01-3.el7 base 56 k perl-Filter x86_64 1.49-3.el7 base 76 k perl-Getopt-Long noarch 2.40-3.el7 base 56 k perl-HTTP-Tiny noarch 0.033-3.el7 base 38 k perl-PathTools x86_64 3.40-5.el7 base 82 k perl-Pod-Escapes noarch 1:1.04-293.el7 base 51 k perl-Pod-Perldoc noarch 3.20-4.el7 base 87 k perl-Pod-Simple noarch 1:3.28-4.el7 base 216 k perl-Pod-Usage noarch 1.63-3.el7 base 27 k perl-Scalar-List-Utils x86_64 1.27-248.el7 base 36 k perl-Socket x86_64 2.010-4.el7 base 49 k perl-Storable x86_64 2.45-3.el7 base 77 k perl-Text-ParseWords noarch 3.29-4.el7 base 14 k perl-Time-HiRes x86_64 4:1.9725-3.el7 base 45 k perl-Time-Local noarch 1.2300-2.el7 base 24 k perl-constant noarch 1.27-2.el7 base 19 k perl-libs x86_64 4:5.16.3-293.el7 base 688 k perl-macros x86_64 4:5.16.3-293.el7 base 44 k perl-parent noarch 1:0.225-244.el7 base 12 k perl-podlators noarch 2.5.1-3.el7 base 112 k perl-threads x86_64 1.87-4.el7 base 49 k perl-threads-shared x86_64 1.43-6.el7 base 39 k xalan-j2 noarch 2.7.1-23.el7 base 1.9 M xerces-j2 noarch 2.11.0-17.el7_0 base 1.1 M xml-commons-apis noarch 1.4.01-16.el7 base 227 k xml-commons-resolver noarch 1.2-15.el7 base 108 k Transaction Summary ================================================================================ Install 1 Package (+32 Dependent packages) Total download size: 26 M Installed size: 83 M Downloading packages: (1/33): perl-Carp-1.26-244.el7.noarch.rpm | 19 kB 00:05 (2/33): perl-Exporter-5.68-3.el7.noarch.rpm | 28 kB 00:02 (3/33): perl-File-Path-2.09-2.el7.noarch.rpm | 26 kB 00:02 (4/33): ant-1.9.4-2.el7.noarch.rpm | 2.0 MB 00:17 (5/33): perl-Filter-1.49-3.el7.x86_64.rpm | 76 kB 00:07 (6/33): perl-5.16.3-293.el7.x86_64.rpm | 8.0 MB 00:27 (7/33): perl-File-Temp-0.23.01-3.el7.noarch.rpm | 56 kB 00:17 (8/33): perl-Getopt-Long-2.40-3.el7.noarch.rpm | 56 kB 00:02 (9/33): perl-Pod-Escapes-1.04-293.el7.noarch.rpm | 51 kB 00:00 (10/33): perl-Pod-Perldoc-3.20-4.el7.noarch.rpm | 87 kB 00:01 (11/33): perl-PathTools-3.40-5.el7.x86_64.rpm | 82 kB 00:03 (12/33): perl-HTTP-Tiny-0.033-3.el7.noarch.rpm | 38 kB 00:03 (13/33): perl-Pod-Usage-1.63-3.el7.noarch.rpm | 27 kB 00:00 (14/33): perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm | 36 kB 00:01 (15/33): perl-Socket-2.010-4.el7.x86_64.rpm | 49 kB 00:01 (16/33): perl-Text-ParseWords-3.29-4.el7.noarch.rpm | 14 kB 00:00 (17/33): perl-Storable-2.45-3.el7.x86_64.rpm | 77 kB 00:01 (18/33): perl-Time-Local-1.2300-2.el7.noarch.rpm | 24 kB 00:00 (19/33): perl-Time-HiRes-1.9725-3.el7.x86_64.rpm | 45 kB 00:01 (20/33): perl-constant-1.27-2.el7.noarch.rpm | 19 kB 00:00 (21/33): perl-macros-5.16.3-293.el7.x86_64.rpm | 44 kB 00:00 (22/33): perl-Pod-Simple-3.28-4.el7.noarch.rpm | 216 kB 00:06 (23/33): perl-parent-0.225-244.el7.noarch.rpm | 12 kB 00:00 (24/33): perl-threads-1.87-4.el7.x86_64.rpm | 49 kB 00:00 (25/33): perl-threads-shared-1.43-6.el7.x86_64.rpm | 39 kB 00:00 (26/33): perl-Encode-2.51-7.el7.x86_64.rpm | 1.5 MB 00:39 (27/33): perl-podlators-2.5.1-3.el7.noarch.rpm | 112 kB 00:04 (28/33): perl-libs-5.16.3-293.el7.x86_64.rpm | 688 kB 00:09 (29/33): java-1.8.0-openjdk-devel-1.8.0.191.b12-1.el7_6.x8 | 9.8 MB 00:48 (30/33): xml-commons-apis-1.4.01-16.el7.noarch.rpm | 227 kB 00:07 (31/33): xalan-j2-2.7.1-23.el7.noarch.rpm | 1.9 MB 00:11 (32/33): xerces-j2-2.11.0-17.el7_0.noarch.rpm | 1.1 MB 00:11 (33/33): xml-commons-resolver-1.2-15.el7.noarch.rpm | 108 kB 00:07 -------------------------------------------------------------------------------- Total 519 kB/s | 26 MB 00:52 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : xml-commons-apis-1.4.01-16.el7.noarch 1/33 Installing : xml-commons-resolver-1.2-15.el7.noarch 2/33 Installing : xalan-j2-2.7.1-23.el7.noarch 3/33 Installing : xerces-j2-2.11.0-17.el7_0.noarch 4/33 Installing : 1:perl-parent-0.225-244.el7.noarch 5/33 Installing : perl-HTTP-Tiny-0.033-3.el7.noarch 6/33 Installing : perl-podlators-2.5.1-3.el7.noarch 7/33 Installing : perl-Pod-Perldoc-3.20-4.el7.noarch 8/33 Installing : 1:perl-Pod-Escapes-1.04-293.el7.noarch 9/33 Installing : perl-Encode-2.51-7.el7.x86_64 10/33 Installing : perl-Text-ParseWords-3.29-4.el7.noarch 11/33 Installing : perl-Pod-Usage-1.63-3.el7.noarch 12/33 Installing : perl-Storable-2.45-3.el7.x86_64 13/33 Installing : perl-Exporter-5.68-3.el7.noarch 14/33 Installing : perl-constant-1.27-2.el7.noarch 15/33 Installing : perl-Carp-1.26-244.el7.noarch 16/33 Installing : 4:perl-macros-5.16.3-293.el7.x86_64 17/33 Installing : perl-Time-Local-1.2300-2.el7.noarch 18/33 Installing : perl-Socket-2.010-4.el7.x86_64 19/33 Installing : 4:perl-Time-HiRes-1.9725-3.el7.x86_64 20/33 Installing : perl-PathTools-3.40-5.el7.x86_64 21/33 Installing : perl-Scalar-List-Utils-1.27-248.el7.x86_64 22/33 Installing : 1:perl-Pod-Simple-3.28-4.el7.noarch 23/33 Installing : perl-File-Temp-0.23.01-3.el7.noarch 24/33 Installing : perl-File-Path-2.09-2.el7.noarch 25/33 Installing : perl-threads-shared-1.43-6.el7.x86_64 26/33 Installing : perl-threads-1.87-4.el7.x86_64 27/33 Installing : perl-Filter-1.49-3.el7.x86_64 28/33 Installing : 4:perl-libs-5.16.3-293.el7.x86_64 29/33 Installing : perl-Getopt-Long-2.40-3.el7.noarch 30/33 Installing : 4:perl-5.16.3-293.el7.x86_64 31/33 Installing : 1:java-1.8.0-openjdk-devel-1.8.0.191.b12-1.el7_6.x86_64 32/33 Installing : ant-1.9.4-2.el7.noarch 33/33 Verifying : perl-HTTP-Tiny-0.033-3.el7.noarch 1/33 Verifying : perl-threads-shared-1.43-6.el7.x86_64 2/33 Verifying : perl-Storable-2.45-3.el7.x86_64 3/33 Verifying : perl-Exporter-5.68-3.el7.noarch 4/33 Verifying : perl-constant-1.27-2.el7.noarch 5/33 Verifying : perl-PathTools-3.40-5.el7.x86_64 6/33 Verifying : perl-Carp-1.26-244.el7.noarch 7/33 Verifying : 4:perl-macros-5.16.3-293.el7.x86_64 8/33 Verifying : xml-commons-resolver-1.2-15.el7.noarch 9/33 Verifying : xml-commons-apis-1.4.01-16.el7.noarch 10/33 Verifying : 1:perl-parent-0.225-244.el7.noarch 11/33 Verifying : perl-File-Temp-0.23.01-3.el7.noarch 12/33 Verifying : 1:perl-Pod-Simple-3.28-4.el7.noarch 13/33 Verifying : perl-Time-Local-1.2300-2.el7.noarch 14/33 Verifying : xerces-j2-2.11.0-17.el7_0.noarch 15/33 Verifying : perl-Socket-2.010-4.el7.x86_64 16/33 Verifying : 1:java-1.8.0-openjdk-devel-1.8.0.191.b12-1.el7_6.x86_64 17/33 Verifying : 4:perl-Time-HiRes-1.9725-3.el7.x86_64 18/33 Verifying : 1:perl-Pod-Escapes-1.04-293.el7.noarch 19/33 Verifying : perl-Scalar-List-Utils-1.27-248.el7.x86_64 20/33 Verifying : ant-1.9.4-2.el7.noarch 21/33 Verifying : xalan-j2-2.7.1-23.el7.noarch 22/33 Verifying : perl-Pod-Usage-1.63-3.el7.noarch 23/33 Verifying : perl-Encode-2.51-7.el7.x86_64 24/33 Verifying : perl-Pod-Perldoc-3.20-4.el7.noarch 25/33 Verifying : perl-podlators-2.5.1-3.el7.noarch 26/33 Verifying : 4:perl-5.16.3-293.el7.x86_64 27/33 Verifying : perl-File-Path-2.09-2.el7.noarch 28/33 Verifying : perl-threads-1.87-4.el7.x86_64 29/33 Verifying : perl-Filter-1.49-3.el7.x86_64 30/33 Verifying : perl-Getopt-Long-2.40-3.el7.noarch 31/33 Verifying : perl-Text-ParseWords-3.29-4.el7.noarch 32/33 Verifying : 4:perl-libs-5.16.3-293.el7.x86_64 33/33 Installed: ant.noarch 0:1.9.4-2.el7 Dependency Installed: java-1.8.0-openjdk-devel.x86_64 1:1.8.0.191.b12-1.el7_6 perl.x86_64 4:5.16.3-293.el7 perl-Carp.noarch 0:1.26-244.el7 perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7 perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7 perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-3.el7 perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-PathTools.x86_64 0:3.40-5.el7 perl-Pod-Escapes.noarch 1:1.04-293.el7 perl-Pod-Perldoc.noarch 0:3.20-4.el7 perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7 perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7 perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7 perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7 perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-293.el7 perl-macros.x86_64 4:5.16.3-293.el7 perl-parent.noarch 1:0.225-244.el7 perl-podlators.noarch 0:2.5.1-3.el7 perl-threads.x86_64 0:1.87-4.el7 perl-threads-shared.x86_64 0:1.43-6.el7 xalan-j2.noarch 0:2.7.1-23.el7 xerces-j2.noarch 0:2.11.0-17.el7_0 xml-commons-apis.noarch 0:1.4.01-16.el7 xml-commons-resolver.noarch 0:1.2-15.el7 Complete!

Verify installation of Java Development Kit (JDK) and Apache Ant.

[root@junit-01 ~]# java -version openjdk version "1.8.0_191" OpenJDK Runtime Environment (build 1.8.0_191-b12) OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode) [root@junit-01 ~]# ant -version Apache Ant(TM) version 1.9.4 compiled on November 5 2018

Java Development Kit (JDK) and Apache Ant are installed on our CentOS 7 system.

 

Install JUnit on CentOS 7:

Install JUnit packages using yum command.

[root@junit-01 ~]# yum install -y junit ant-junit Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: repo.inara.pk * extras: repo.inara.pk * updates: repo.inara.pk Resolving Dependencies --> Running transaction check ---> Package ant-junit.noarch 0:1.9.4-2.el7 will be installed ---> Package junit.noarch 0:4.11-8.el7 will be installed --> Processing Dependency: osgi(org.hamcrest.core) for package: junit-4.11-8.el7.noarch --> Processing Dependency: hamcrest for package: junit-4.11-8.el7.noarch --> Running transaction check ---> Package hamcrest.noarch 0:1.3-6.el7 will be installed --> Processing Dependency: qdox for package: hamcrest-1.3-6.el7.noarch --> Processing Dependency: easymock2 for package: hamcrest-1.3-6.el7.noarch --> Running transaction check ---> Package easymock2.noarch 0:2.5.2-12.el7 will be installed ---> Package qdox.noarch 0:1.12.1-10.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: ant-junit noarch 1.9.4-2.el7 base 145 k junit noarch 4.11-8.el7 base 261 k Installing for dependencies: easymock2 noarch 2.5.2-12.el7 base 92 k hamcrest noarch 1.3-6.el7 base 124 k qdox noarch 1.12.1-10.el7 base 170 k Transaction Summary ================================================================================ Install 2 Packages (+3 Dependent packages) Total download size: 792 k Installed size: 1.0 M Downloading packages: (1/5): easymock2-2.5.2-12.el7.noarch.rpm | 92 kB 00:00 (2/5): junit-4.11-8.el7.noarch.rpm | 261 kB 00:01 (3/5): qdox-1.12.1-10.el7.noarch.rpm | 170 kB 00:01 (4/5): ant-junit-1.9.4-2.el7.noarch.rpm | 145 kB 00:02 (5/5): hamcrest-1.3-6.el7.noarch.rpm | 124 kB 00:04 -------------------------------------------------------------------------------- Total 175 kB/s | 792 kB 00:04 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : easymock2-2.5.2-12.el7.noarch 1/5 Installing : qdox-1.12.1-10.el7.noarch 2/5 Installing : hamcrest-1.3-6.el7.noarch 3/5 Installing : junit-4.11-8.el7.noarch 4/5 Installing : ant-junit-1.9.4-2.el7.noarch 5/5 Verifying : hamcrest-1.3-6.el7.noarch 1/5 Verifying : easymock2-2.5.2-12.el7.noarch 2/5 Verifying : ant-junit-1.9.4-2.el7.noarch 3/5 Verifying : qdox-1.12.1-10.el7.noarch 4/5 Verifying : junit-4.11-8.el7.noarch 5/5 Installed: ant-junit.noarch 0:1.9.4-2.el7 junit.noarch 0:4.11-8.el7 Dependency Installed: easymock2.noarch 0:2.5.2-12.el7 hamcrest.noarch 0:1.3-6.el7 qdox.noarch 0:1.12.1-10.el7 Complete!

 

Create a Java Project:

Create a directory structure to store Java source and build files. Please read our previous article Install and Build with Apache ANT on RHEL/CentOS 7.6

[root@junit-01 ~]# mkdir -p ~/myMathApp/{src/myMathApp,build/classes,build/jar}

Now, Write some Java code.

[root@junit-01 ~]# vi ~/myMathApp/src/myMathApp/Calculate.java

We write a class Calculate, that perform some basic arithmatic operations. The Java code is as follows:

package myMathApp; public class Calculate { public int sum(int num1, int num2) { return num1 + num2; } public int average(int num1, int num2, int num3) { return (num1 + num2 + num3)/3; } }

Create an Apache Ant build.xml file to compile and run this code with ant command.

[root@junit-01 myMathApp]# vi ~/myMathApp/build.xml

We are using the same build.xml script that we have used in our previous article.

<project default="run"> <target name="clean"> <delete dir="build" /> </target> <target name="compile" depends="clean"> <mkdir dir="build/classes" /> <javac srcdir="src" destdir="build/classes" includeantruntime="yes" /> </target> <target name="jar" depends="compile"> <mkdir dir="build/jar" /> <jar destfile="build/jar/myMathApp.jar" basedir="build/classes"> <manifest> <attribute name="Main-Class" value="myMathApp.Calculate" /> </manifest> </jar> </target> <target name="run" depends="jar"> <java jar="build/jar/myMathApp.jar" fork="true" /> </target> </project>

You may have notice that, we have adjusted some parameters in build.xml file according to our project.

[root@junit-01 ~]# cd ~/myMathApp/ [root@junit-01 myMathApp]# ant Buildfile: /root/myMathApp/build.xml clean: [delete] Deleting directory /root/myMathApp/build compile: [mkdir] Created dir: /root/myMathApp/build/classes [javac] Compiling 1 source file to /root/myMathApp/build/classes jar: [mkdir] Created dir: /root/myMathApp/build/jar [jar] Building jar: /root/myMathApp/build/jar/myMathApp.jar run: [java] Error: Main method not found in class myMathApp.Calculate, please define the main method as: [java] public static void main(String[] args) [java] or a JavaFX application class must extend javafx.application.Application [java] Java Result: 1 BUILD SUCCESSFUL Total time: 1 second

Here run target is throwing an error, because our Java Class lacks a main procedure. There is no need to worry, we already know that, therefore, just ignore this error.

Our Java project is successfully compiled and built with Apache Ant here.

Now, write another Java Class to perform unit testing of our Calculate class.

[root@junit-01 myMathApp]# vi ~/myMathApp/src/myMathApp/CalculateTest.java

We have write another class CalculateTest for testing Calculate class as follows:

package myMathApp; import org.junit.Test; import static org.junit.Assert.*; public class CalculateTest { Calculate Calculator = new Calculate(); @Test public void testSum() { int sum = Calculator.sum(2,5); int testsum = 7; assertEquals(sum, testsum); } @Test public void testaverage() { int average = Calculator.average(9, 18, 27); int testaverage = 18; assertEquals(average, testaverage); } }

Copy junit class libraries to Project's lib directory.

[root@junit-01 myMathApp]# mkdir ~/myMathApp/lib [root@junit-01 myMathApp]# cp /usr/share/java/junit* lib/ [root@junit-01 myMathApp]# cp /usr/share/java/ant/ant-junit* lib/

Edit build.xml file to include lib directory to compile target.

<project default="run"> <target name="clean"> <delete dir="build" /> </target> <path id="classpath"> <fileset dir="lib" includes="**/.jar" /> </path> <target name="compile" depends="clean"> <mkdir dir="build/classes" /> <javac srcdir="src" destdir="build/classes" classpathref="classpath" includeantruntime="yes" /> </target> <target name="jar" depends="compile"> <mkdir dir="build/jar" /> <jar destfile="build/jar/myMathApp.jar" basedir="build/classes"> <manifest> <attribute name="Main-Class" value="myMathApp.Calculate" /> </manifest> </jar> </target> <target name="run" depends="jar"> <java jar="build/jar/myMathApp.jar" fork="true" /> </target> </project>

Run ant command again.

[root@junit-01 myMathApp]# ant Buildfile: /root/myMathApp/build.xml clean: [delete] Deleting directory /root/myMathApp/build compile: [mkdir] Created dir: /root/myMathApp/build/classes [javac] Compiling 2 source files to /root/myMathApp/build/classes jar: [mkdir] Created dir: /root/myMathApp/build/jar [jar] Building jar: /root/myMathApp/build/jar/myMathApp.jar run: [java] Error: Main method not found in class myMathApp.Calculate, please define the main method as: [java] public static void main(String[] args) [java] or a JavaFX application class must extend javafx.application.Application [java] Java Result: 1 BUILD SUCCESSFUL Total time: 1 second

Include a test target in build.xml file to perform unit testing with JUnit.

<project default="run"> <target name="clean"> <delete dir="build" /> </target> <path id="classpath"> <fileset dir="lib" includes="**/.jar" /> </path> <target name="compile" depends="clean"> <mkdir dir="build/classes" /> <javac srcdir="src" destdir="build/classes" classpathref="classpath" includeantruntime="yes" /> </target> <target name="test" depends="jar"> <junit printsummary="yes"> <classpath> <path refid="classpath" /> <path location="build/jar/myMathApp.jar" /> </classpath> <batchtest fork="yes"> <fileset dir="src" includes="**/*Test.java" /> </batchtest> </junit> </target> <target name="jar" depends="compile"> <mkdir dir="build/jar" /> <jar destfile="build/jar/myMathApp.jar" basedir="build/classes"> <manifest> <attribute name="Main-Class" value="myMathApp.Calculate" /> </manifest> </jar> </target> <target name="run" depends="jar"> <java jar="build/jar/myMathApp.jar" fork="true" /> </target> </project>

Run Ant Job for test target.

[root@junit-01 myMathApp]# ant test Buildfile: /root/myMathApp/build.xml clean: [delete] Deleting directory /root/myMathApp/build compile: [mkdir] Created dir: /root/myMathApp/build/classes [javac] Compiling 2 source files to /root/myMathApp/build/classes jar: [mkdir] Created dir: /root/myMathApp/build/jar [jar] Building jar: /root/myMathApp/build/jar/myMathApp.jar test: [junit] Running myMathApp.CalculateTest [junit] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.018 sec BUILD SUCCESSFUL Total time: 1 second

test target performs two tests and both tests are successful.

To test it, produce a logical error in Calculate.java class.

package myMathApp; public class Calculate { public int sum(int num1, int num2) { return num1 - num2; } public int average(int num1, int num2, int num3) { return (num1 + num2 + num3)/2; } }

Run Ant Job again after producing some logical errors in Calculate.java.

[root@junit-01 myMathApp]# ant test Buildfile: /root/myMathApp/build.xml clean: [delete] Deleting directory /root/myMathApp/build compile: [mkdir] Created dir: /root/myMathApp/build/classes [javac] Compiling 2 source files to /root/myMathApp/build/classes jar: [mkdir] Created dir: /root/myMathApp/build/jar [jar] Building jar: /root/myMathApp/build/jar/myMathApp.jar test: [junit] Running myMathApp.CalculateTest [junit] Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.023 sec [junit] Test myMathApp.CalculateTest FAILED BUILD SUCCESSFUL Total time: 2 seconds

You may notice that, both tests are FAILED now.

We have successfully install and integrate Apache Ant with JUnit on CentOS 7.

JUnit: Integrate with Apache Ant on CentOS 7


YOU MIGHT ALSO LIKE:

No comments:

Post a Comment