BogoToBogo
  • Home
  • About
  • Big Data
  • Machine Learning
  • AngularJS
  • Python
  • C++
  • go
  • DevOps
  • Kubernetes
  • Algorithms
  • More...
    • Qt 5
    • Linux
    • FFmpeg
    • Matlab
    • Django 1.8
    • Ruby On Rails
    • HTML5 & CSS

JUnit 4 Tutorial: Introcution (Hello World) - 2020

Duke 512




Bookmark and Share





bogotobogo.com site search:




Java Environment

Java:

$ java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.1) (7u65-2.5.1-4ubuntu1~0.14.04.2)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)

JAVA_HOME:

$ which javac
/usr/bin/javac

$ readlink -f /usr/bin/javac
/usr/lib/jvm/java-7-openjdk-amd64/bin/javac

Add JAVA_HOME and System path to ~/.bashrc:

  • Set JAVA_HOME, using the path just before the bin folder:
    export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
    
  • Append Java compiler location to System Path:
    export PATH=$PATH:$JAVA_HOME/bin/
    

Run shell:

source ~/.bashrc




JUnit Environment

Download latest version of JUnit jar file
from https://github.com/junit-team/junit/wiki/Download-and-Install.
At the time of writing this tutorial, 'junit-4.11.jar' is the latest stable version.

We need 'hamcrest-core-1.3.jar' as well.

Put them into ~/usr/local/JUNIT.


Set the JUNIT_HOME environment variable to point to the base directory location where JUNIT jar is stored:

export JUNIT_HOME=/usr/local/JUNIT

Set the CLASSPATH environment variable to point to the JUNIT jar location:

export CLASSPATH=$CLASSPATH:$JUNIT_HOME/junit-4.11.jar
export CLASSPATH=$CLASSPATH:$JUNIT_HOME/hamcrest-core-1.3.jar

We may need to give permission to those jar files:

sudo chmod +r *.jar

Run shell:

source ~/.bashrc




Setup JUnit test

Create a java class file name TestJunit in ~/JUNIT/workspace:

import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestJunit {
   @Test
   public void testString() {
      String str= "Junit, Hello world!" ;
      assertEquals("Junit, Hello world!",str);
   }
}

Create a java class file name TestRunner in ~/JUNIT/workspace to execute Test case(s)

import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

public class TestRunner {
   public static void main(String[] args) {
      Result result = JUnitCore.runClasses(TestJunit.class);
      for (Failure failure : result.getFailures()) {
         System.out.println(failure.toString());
      }
      System.out.println(result.wasSuccessful());
   }
}  	




Run JUnit test
$ javac TestJunit.java TestRunner.java
$ java TestRunner
true



JUnit & Maven Tutorial

  • JUnit 4 Introduction (Hello World)
  • JUnit 4 Test with Eclipse Luna (Hello World)
  • JUnit 4 Test with Maven (Hello World)








  • Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization

    YouTubeMy YouTube channel

    Sponsor Open Source development activities and free contents for everyone.

    Thank you.

    - K Hong







    JUnit & Maven Tutorial



    JUnit 4 Introduction (Hello World)

    JUnit 4 Test with Eclipse Luna (Hello World)

    JUnit 4 Test with Maven (Hello World)




    Sponsor Open Source development activities and free contents for everyone.

    Thank you.

    - K Hong







    Scala Play!



    Scala/Java Play app with Angular





    Spring Boot



    Spring Boot : Hello world with Mavan 3

    Spring Boot : Hello world with Gradle 2

    Spring Boot (Gradle 2) : Hello world with Authentication

    Spring Boot : Deploying War file to Tomcat 8's webapps

    How to Setup Apache as Reverse Proxy for Tomcat Server using mod proxy

    Maven : mvn command cheat sheet

    Spring-Boot REST API with CORS App Maven war file deploy to Tomcat

    Spring-Boot / Spring Security with AngularJS - Part I (Introduction)

    Spring-Boot / Spring Security with AngularJS - Part II (Dynamic resource load from Angular)

    Spring-Boot / Spring Security with AngularJS : Part III (Form-based Authentication)





    Java Tutorials



    Java Tutorial Home

    Basics - Compiling and Launching

    Inner Classes

    Constructor

    Enums

    Static & Finally

    Default and Protected

    Polymorphism

    Exception Handling

    Exception Handling II

    String Class

    Threads

    Threads II - State Transition

    Threads III - Synchronization

    Object Class

    File I/O

    Serialization

    ArrayList

    Autoboxing

    Java Graphics Interface I - Basics

    Java Graphics Interface II - Labels, Text Fields, Layouts

    Java Graphics Interface III - paintComponent

    TCP Sockets Server/Client

    Scala - Functional Java Programming

    Apache CXF install

    Tomcat 7 Ubuntu 14 Install on Amazon EC2 instance

    What is Apache Maven?

    Maven life cycle

    Eclipse Maven 3 plugin on Ubuntu 14.04

    Apache Maven 3 - Setting up and creating a project

    Apache Maven 3 - Compile, build, and install a Maven project

    Apache Maven 3 - Dependencies

    Apache Maven 3 - Web Application

    Apache Maven 3 - Plugins (compiler)

    Apache Maven 3 - Plugins (Jetty)

    Eclipse CDT / JNI (Java Native Interface) / MinGW



    Spring Framework

    Hello World App with Spring 4 & Maven 3 - Part I











    Contact

    BogoToBogo
    contactus@bogotobogo.com

    Follow Bogotobogo

    About Us

    contactus@bogotobogo.com

    YouTubeMy YouTube channel
    Pacific Ave, San Francisco, CA 94115

    Pacific Ave, San Francisco, CA 94115

    Copyright © 2024, bogotobogo
    Design: Web Master