SlideShare a Scribd company logo
Build, Logging, and Unit Test
Tools
Allan Huang @ Delta DRC
Agenda
 Build Tool
◦ Maven
 Logging Tool
◦ Log4J 2 and SLF4J
 Unit Test Tool
◦ JUnit 4
Build Tool
What is Maven?
 Aspects of building software
◦ How software is built?
◦ What are its dependencies?
 Convention over Configuration
 Maven
◦ Software project management tool
◦ Build-automation tool
 Manage project’s build, dependency
and documentation
Maven Overview
Standard Directory Layout (1)
 src/main
◦ Contains all of the code and resources needed
for building the artifact.
◦ src/main/java
 Contains the deliverable Java source code for the project.
◦ src/main/resources
 Contains any configuration files, data files, or Java
properties to include in the bundle.
◦ src/main/scripts
 Contains some kinds of application usage scripts, e.g.
windows batch script, Linux shell script.
◦ src/main/webapp
 Contains your Java web application, if your project is a
web application. It is the root directory of the web
application.
Standard Directory Layout (2)
 src/test
◦ Contains all of the code and resources for running unit
tests against the compiled artifact.
◦ src/test/java
 Contains the testing Java source code (JUnit or TestNG test cases,
for example) for the project.
◦ src/test/resources
 Contains resources necessary for testing.
 src/assembly
◦ Contains some assembly descriptors for creating
distributions in the target directory.
 target
◦ It is used to house all output of the build.
 pom.xml
◦ The top level files descriptive of the project.
Dependency Scope
 Compile
◦ Compile dependencies are available in all class-paths of a
project.
 Provided
◦ Indicates you expect the JDK or a container to provide the
dependency at runtime.
 Runtime
◦ Indicates that the dependency is not required for
compilation, but is for execution.
 Test
◦ Indicates that the dependency is only available for the test
compilation and execution phases.
 System
◦ You have to provide the JAR which contains it explicitly.
The artifact is always available and is not looked up in a
repository.
Build Lifecycle
 Clean
◦ Remove all files generated by the
previous build.
 Default
◦ validate → compile → test → package →
integration-test → verify → install →
deploy
 Site
◦ Generates the project's site
documentation.
Default Lifecycle (1)
 Validate
◦ validate the project is correct and all necessary
information is available.
 Compile
◦ Compile the source code of the project.
 Test
◦ Test the compiled source code using a suitable
unit testing framework.
◦ These tests should not require the code be
packaged or deployed.
 Package
◦ Take the compiled code and package it in its
distributable format, such as a JAR.
Default Lifecycle (2)
 Integration-test
◦ Process and deploy the package if necessary
into an environment where integration tests can
be run.
 Verify
◦ Run any checks to verify the package is valid
and meets quality criteria.
 Install
◦ Install the package into the local repository, for
use as a dependency in other projects locally.
 Deploy
◦ Done in an integration or release environment,
copies the final package to the remote repository
for sharing with other developers and projects.
POM
 Project Object Model (POM)
◦ Contains a complete description of how to
build the current project.
◦ pom.xml
 Effective POM
 Parent/Super POM and Sub POM
Repository Type
 Local repository
 Remote repository
 Maven Central
repository
◦ http://search.maven.o
rg
Build with Maven
 Environment Setup
◦ Set JAVA_HOME
◦ Set M2_HOME
◦ Add M2_HOME/bin to System PATH
◦ Verify with command line
 mvn –version
 Local Repository Setting
◦ M2_HOME/conf/settings.xml
 localRepository & proxies setting
 Build projects with command line
◦ mvn (default goal)
 Target
◦ Classes, Test-classes, Test reports, JAR, WAR, etc.
Reference
 Apache Maven
 Maven Tutorial
 Introduction to the Standard Directory
Layout
 Maven Directory Structure
 Introduction to the Dependency
Mechanism
 Introduction to the Build Lifecycle
 Maven in 5 Minutes
 Maven - Environment Setup
Logging Tool
What is Log4J 2?
 A fast and flexible framework for
logging application debugging
messages.
 Logging behavior can be controlled by
editing a configuration file, without
touching the application binary.
 Log4j 2 is an upgrade to Log4j.
What is SLF4J?
 Simple Logging Facade for Java
◦ Serves as a simple facade or abstraction
for various logging frameworks allowing
the end user to plug in the desired logging
framework at deployment time.
 Well-known logging frameworks
◦ Log4j 2, Log4j
◦ Logback
◦ Java Util Logging
SLF4J bound to Log4J
SLF4J, JDK Logging and
Log4J 2
Log Level
 ERROR (be suited for Production environment)
◦ Something terribly wrong had happened, that must be
investigated immediately.
 e.g. Null pointer, Database unavailable, Mission critical.
 WARN (be suited for Production environment)
◦ The process might be continued, but take extra caution.
 e.g. Database connection lost, Socket reaching to its limit.
 INFO (be suited for Test/QA environment)
◦ Important process has finished. Then quickly find out what
the application is doing.
 e.g. Server has been started, Incoming messages, Outgoing
messages.
 DEBUG (be suited for Development environment)
◦ It is used by the developers to debug the systems.
 ALL, FATAL, TRACE, OFF levels are rarely used.
SLF4J Common API
 private static final Logger log =
LoggerFactory.getLogger(UserServiceImpl.class);
 void debug(String msg)
 void debug(String format, Object... arguments)
 void debug(String msg, Throwable t)
 void info(String msg)
 void info(String format, Object... arguments)
 void info(String msg, Throwable t)
 void warn(String msg)
 void warn(String format, Object... arguments)
 void warn(String msg, Throwable t)
 void error(String msg)
 void error(String format, Object... arguments)
 void error(String msg, Throwable t)
Log4J 2 Configuration (1)
 log4j2.xml
 Appenders
◦ Console Appender
◦ Rolling File Appender
 OnStartup Triggering Policy
 SizeBased Triggering Policy
 TimeBased Triggering Policy
 Loggers
 Root Logger
 Named Logger
 Named Hierarchy
Log4J 2 Configuration (2)
Logging Tips (1)
 Use the appropriate tools for the job
◦ log.debug("Found {} records matching filter: '{}'", records, filter);
 Don’t forget, logging levels are there
for you
 Do you know what you are logging?
◦ log.debug("Processing request with id: {}", request.getId());
◦ log.debug("Returning users: {}", users);
 Avoid side effects
◦ try {
log.trace("Id=" + request.getUser().getId() + " accesses " +
manager.getPage().getUrl().toString())
} catch(NullPointerException e) {
}
Logging Tips (2)
 Be concise and descriptive
◦ log.debug("Message processed");
log.debug(message.getJMSMessageID());
log.debug("Message with id '{}' processed",
message.getJMSMessageID());
 Tune your pattern in log4j2.xml
 Log method arguments and return values
 Watch out for external systems
◦ Communicates with an external system, consider logging every
piece of data that comes out from your application and gets in.
Logging Tips (3)
 Log exceptions properly
 Logs easy to read, easy to parse
Reference
 Frequently Asked Questions about
SLF4J
 FAQ about Log4j 2
 SLF4J Logger API
 Log4J 2 Appenders
 log4j2 xml configuration example
 10 Tips for Proper Application Logging
 Logging Anti-Patterns
 Logging in Java with slf4j
Unit Test Tool
What is JUnit 4?
 A simple unit testing framework to
write repeatable tests for Java.
 Test-Driven Development (TDD)
◦ Test-first Development
◦ High Code Coverage
 A static main method vs. Unit test
cases
 JUnit 4 is an upgrade to JUnit 3.
JUnit Execution Order
Generate a Test Class
JUnit 4 Features
JUnit 4 Assert method
 assertArrayEquals(message, expecteds, actuals)
◦ Tests whether two arrays are equal to each other.
 assertEquals(message, expected, actual)
◦ Compares two objects for equality, using their equals() method.
 assertTrue(message, condition) & assertFalse(message, condition)
◦ Tests a single variable to see if its value is either true, or false.
 assertNull(message, object) & assertNotNull(message, object)
◦ Tests a single variable to see if it is null or not null.
 assertSame(message, expected, actual) & assertNotSame(message,
unexpected, actual)
◦ Tests if two object references point to the same object or not.
 assertThat(message, actual, matcher)
◦ Compares an object to an org.hamcrest.Matcher to see if the given object matches
whatever the Matcher requires it to match.
 fail(message)
◦ Fails a test with the given message.
Reference
 JUnit
 Junit 3 vs Junit 4 Comparison
 Assert Methods
 Assert (JUnit API)
Q & A
Ad

More Related Content

What's hot (20)

Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and Trends
Carol McDonald
 
De Java 8 a Java 17
De Java 8 a Java 17De Java 8 a Java 17
De Java 8 a Java 17
Víctor Leonel Orozco López
 
Top 30 Node.js interview questions
Top 30 Node.js interview questionsTop 30 Node.js interview questions
Top 30 Node.js interview questions
techievarsity
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in android
Rakesh Jha
 
Java Concurrency in Practice
Java Concurrency in PracticeJava Concurrency in Practice
Java Concurrency in Practice
Alina Dolgikh
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/Multitasking
Sasha Kravchuk
 
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Christian Schneider
 
What's new in Java 11
What's new in Java 11What's new in Java 11
What's new in Java 11
Michel Schudel
 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
Rafael Winterhalter
 
Wait for your fortune without Blocking!
Wait for your fortune without Blocking!Wait for your fortune without Blocking!
Wait for your fortune without Blocking!
Roman Elizarov
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
Ryan Cuprak
 
Concurrency Programming in Java - 07 - High-level Concurrency objects, Lock O...
Concurrency Programming in Java - 07 - High-level Concurrency objects, Lock O...Concurrency Programming in Java - 07 - High-level Concurrency objects, Lock O...
Concurrency Programming in Java - 07 - High-level Concurrency objects, Lock O...
Sachintha Gunasena
 
[Java concurrency]01.thread management
[Java concurrency]01.thread management[Java concurrency]01.thread management
[Java concurrency]01.thread management
xuehan zhu
 
Quick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android DevQuick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android Dev
Shuhei Shogen
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
Nir Noy
 
Logging with Logback in Scala
Logging with Logback in ScalaLogging with Logback in Scala
Logging with Logback in Scala
Knoldus Inc.
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
Minh Hoang
 
JAVA BYTE CODE
JAVA BYTE CODEJAVA BYTE CODE
JAVA BYTE CODE
Javed Ahmed Samo
 
JProfiler8 @ OVIRT
JProfiler8 @ OVIRTJProfiler8 @ OVIRT
JProfiler8 @ OVIRT
Liran Zelkha
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
Hoang Nguyen
 
Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and Trends
Carol McDonald
 
Top 30 Node.js interview questions
Top 30 Node.js interview questionsTop 30 Node.js interview questions
Top 30 Node.js interview questions
techievarsity
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in android
Rakesh Jha
 
Java Concurrency in Practice
Java Concurrency in PracticeJava Concurrency in Practice
Java Concurrency in Practice
Alina Dolgikh
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/Multitasking
Sasha Kravchuk
 
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Christian Schneider
 
Wait for your fortune without Blocking!
Wait for your fortune without Blocking!Wait for your fortune without Blocking!
Wait for your fortune without Blocking!
Roman Elizarov
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
Ryan Cuprak
 
Concurrency Programming in Java - 07 - High-level Concurrency objects, Lock O...
Concurrency Programming in Java - 07 - High-level Concurrency objects, Lock O...Concurrency Programming in Java - 07 - High-level Concurrency objects, Lock O...
Concurrency Programming in Java - 07 - High-level Concurrency objects, Lock O...
Sachintha Gunasena
 
[Java concurrency]01.thread management
[Java concurrency]01.thread management[Java concurrency]01.thread management
[Java concurrency]01.thread management
xuehan zhu
 
Quick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android DevQuick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android Dev
Shuhei Shogen
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
Nir Noy
 
Logging with Logback in Scala
Logging with Logback in ScalaLogging with Logback in Scala
Logging with Logback in Scala
Knoldus Inc.
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
Minh Hoang
 
JProfiler8 @ OVIRT
JProfiler8 @ OVIRTJProfiler8 @ OVIRT
JProfiler8 @ OVIRT
Liran Zelkha
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
Hoang Nguyen
 

Viewers also liked (11)

Well logging
Well loggingWell logging
Well logging
Geology Department, Faculty of Science, Tanta University
 
science behind well logging_dileep p allavarapu
science behind well logging_dileep p allavarapuscience behind well logging_dileep p allavarapu
science behind well logging_dileep p allavarapu
knigh7
 
Logging for Production Systems in The Container Era
Logging for Production Systems in The Container EraLogging for Production Systems in The Container Era
Logging for Production Systems in The Container Era
Sadayuki Furuhashi
 
REGISTROS PLT GRUPO H2
REGISTROS PLT GRUPO H2 REGISTROS PLT GRUPO H2
REGISTROS PLT GRUPO H2
Ismael Betancourt
 
Registro de Producción (PLT)
Registro de Producción (PLT)Registro de Producción (PLT)
Registro de Producción (PLT)
Ulise Alcala
 
Q921 log lec3 v1
Q921 log lec3 v1Q921 log lec3 v1
Q921 log lec3 v1
AFATous
 
well logging tools and exercise_dileep p allavarapu
well logging tools and exercise_dileep p allavarapuwell logging tools and exercise_dileep p allavarapu
well logging tools and exercise_dileep p allavarapu
knigh7
 
Q921 log lec2 v1
Q921 log lec2 v1Q921 log lec2 v1
Q921 log lec2 v1
AFATous
 
Basic well log interpretation
Basic well log interpretationBasic well log interpretation
Basic well log interpretation
Shahnawaz Mustafa
 
Well logging analysis: methods and interpretation
Well logging analysis: methods and interpretationWell logging analysis: methods and interpretation
Well logging analysis: methods and interpretation
Cristiano Ascolani
 
registro de pozoz
registro de pozozregistro de pozoz
registro de pozoz
opulento22
 
science behind well logging_dileep p allavarapu
science behind well logging_dileep p allavarapuscience behind well logging_dileep p allavarapu
science behind well logging_dileep p allavarapu
knigh7
 
Logging for Production Systems in The Container Era
Logging for Production Systems in The Container EraLogging for Production Systems in The Container Era
Logging for Production Systems in The Container Era
Sadayuki Furuhashi
 
Registro de Producción (PLT)
Registro de Producción (PLT)Registro de Producción (PLT)
Registro de Producción (PLT)
Ulise Alcala
 
Q921 log lec3 v1
Q921 log lec3 v1Q921 log lec3 v1
Q921 log lec3 v1
AFATous
 
well logging tools and exercise_dileep p allavarapu
well logging tools and exercise_dileep p allavarapuwell logging tools and exercise_dileep p allavarapu
well logging tools and exercise_dileep p allavarapu
knigh7
 
Q921 log lec2 v1
Q921 log lec2 v1Q921 log lec2 v1
Q921 log lec2 v1
AFATous
 
Basic well log interpretation
Basic well log interpretationBasic well log interpretation
Basic well log interpretation
Shahnawaz Mustafa
 
Well logging analysis: methods and interpretation
Well logging analysis: methods and interpretationWell logging analysis: methods and interpretation
Well logging analysis: methods and interpretation
Cristiano Ascolani
 
registro de pozoz
registro de pozozregistro de pozoz
registro de pozoz
opulento22
 
Ad

Similar to Build, logging, and unit test tools (20)

Selenium Training in Chennai
Selenium Training in ChennaiSelenium Training in Chennai
Selenium Training in Chennai
Thecreating Experts
 
Comparative Development Methodologies
Comparative Development MethodologiesComparative Development Methodologies
Comparative Development Methodologies
elliando dias
 
Basic Java I
Basic Java IBasic Java I
Basic Java I
SSN College of Engineering, Kalavakkam
 
What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)
Shaharyar khan
 
Introduction java programming
Introduction java programmingIntroduction java programming
Introduction java programming
Nanthini Kempaiyan
 
Java JDK.docx
Java JDK.docxJava JDK.docx
Java JDK.docx
Bornali Das
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
Ortus Solutions, Corp
 
2 22CA026_Advance Java Programming_Data types and Operators.pptx
2 22CA026_Advance Java Programming_Data types and Operators.pptx2 22CA026_Advance Java Programming_Data types and Operators.pptx
2 22CA026_Advance Java Programming_Data types and Operators.pptx
dolphiverma80
 
Automation using ibm rft
Automation using ibm rftAutomation using ibm rft
Automation using ibm rft
Prashant Chaudhary
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rd
prat0ham
 
brief introduction to core java programming.pptx
brief introduction to core java programming.pptxbrief introduction to core java programming.pptx
brief introduction to core java programming.pptx
ansariparveen06
 
java slides
java slidesjava slides
java slides
RizwanTariq18
 
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Dan Allen
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
Sujit Majety
 
Cypress Testing.pptx
Cypress Testing.pptxCypress Testing.pptx
Cypress Testing.pptx
JasmeenShrestha
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
Murugesh33
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
Murugesh33
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
Mohit Gupta
 
Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introduction
Sergii Fesenko
 
Comparative Development Methodologies
Comparative Development MethodologiesComparative Development Methodologies
Comparative Development Methodologies
elliando dias
 
What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)
Shaharyar khan
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
Ortus Solutions, Corp
 
2 22CA026_Advance Java Programming_Data types and Operators.pptx
2 22CA026_Advance Java Programming_Data types and Operators.pptx2 22CA026_Advance Java Programming_Data types and Operators.pptx
2 22CA026_Advance Java Programming_Data types and Operators.pptx
dolphiverma80
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rd
prat0ham
 
brief introduction to core java programming.pptx
brief introduction to core java programming.pptxbrief introduction to core java programming.pptx
brief introduction to core java programming.pptx
ansariparveen06
 
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Dan Allen
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
Sujit Majety
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
Murugesh33
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
Murugesh33
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
Mohit Gupta
 
Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introduction
Sergii Fesenko
 
Ad

More from Allan Huang (20)

Drools
DroolsDrools
Drools
Allan Huang
 
Netty 4-based RPC System Development
Netty 4-based RPC System DevelopmentNetty 4-based RPC System Development
Netty 4-based RPC System Development
Allan Huang
 
eSobi Website Multilayered Architecture
eSobi Website Multilayered ArchitectureeSobi Website Multilayered Architecture
eSobi Website Multilayered Architecture
Allan Huang
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New Evolution
Allan Huang
 
JQuery New Evolution
JQuery New EvolutionJQuery New Evolution
JQuery New Evolution
Allan Huang
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Allan Huang
 
Boilerpipe Integration And Improvement
Boilerpipe Integration And ImprovementBoilerpipe Integration And Improvement
Boilerpipe Integration And Improvement
Allan Huang
 
YQL Case Study
YQL Case StudyYQL Case Study
YQL Case Study
Allan Huang
 
Build Cross-Platform Mobile Application with PhoneGap
Build Cross-Platform Mobile Application with PhoneGapBuild Cross-Platform Mobile Application with PhoneGap
Build Cross-Platform Mobile Application with PhoneGap
Allan Huang
 
HTML5 Multithreading
HTML5 MultithreadingHTML5 Multithreading
HTML5 Multithreading
Allan Huang
 
HTML5 Offline Web Application
HTML5 Offline Web ApplicationHTML5 Offline Web Application
HTML5 Offline Web Application
Allan Huang
 
HTML5 Data Storage
HTML5 Data StorageHTML5 Data Storage
HTML5 Data Storage
Allan Huang
 
Java Script Patterns
Java Script PatternsJava Script Patterns
Java Script Patterns
Allan Huang
 
Weighted feed recommand
Weighted feed recommandWeighted feed recommand
Weighted feed recommand
Allan Huang
 
Web Crawler
Web CrawlerWeb Crawler
Web Crawler
Allan Huang
 
eSobi Site Initiation
eSobi Site InitiationeSobi Site Initiation
eSobi Site Initiation
Allan Huang
 
Architecture of eSobi club based on J2EE
Architecture of eSobi club based on J2EEArchitecture of eSobi club based on J2EE
Architecture of eSobi club based on J2EE
Allan Huang
 
J2EE Performance Monitor (Profiler)
J2EE Performance Monitor (Profiler)J2EE Performance Monitor (Profiler)
J2EE Performance Monitor (Profiler)
Allan Huang
 
Search is not only search
Search is not only searchSearch is not only search
Search is not only search
Allan Huang
 
Issue tracking workflow in web development and maintenance cycle
Issue tracking workflow in web development and maintenance cycleIssue tracking workflow in web development and maintenance cycle
Issue tracking workflow in web development and maintenance cycle
Allan Huang
 
Netty 4-based RPC System Development
Netty 4-based RPC System DevelopmentNetty 4-based RPC System Development
Netty 4-based RPC System Development
Allan Huang
 
eSobi Website Multilayered Architecture
eSobi Website Multilayered ArchitectureeSobi Website Multilayered Architecture
eSobi Website Multilayered Architecture
Allan Huang
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New Evolution
Allan Huang
 
JQuery New Evolution
JQuery New EvolutionJQuery New Evolution
JQuery New Evolution
Allan Huang
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Allan Huang
 
Boilerpipe Integration And Improvement
Boilerpipe Integration And ImprovementBoilerpipe Integration And Improvement
Boilerpipe Integration And Improvement
Allan Huang
 
Build Cross-Platform Mobile Application with PhoneGap
Build Cross-Platform Mobile Application with PhoneGapBuild Cross-Platform Mobile Application with PhoneGap
Build Cross-Platform Mobile Application with PhoneGap
Allan Huang
 
HTML5 Multithreading
HTML5 MultithreadingHTML5 Multithreading
HTML5 Multithreading
Allan Huang
 
HTML5 Offline Web Application
HTML5 Offline Web ApplicationHTML5 Offline Web Application
HTML5 Offline Web Application
Allan Huang
 
HTML5 Data Storage
HTML5 Data StorageHTML5 Data Storage
HTML5 Data Storage
Allan Huang
 
Java Script Patterns
Java Script PatternsJava Script Patterns
Java Script Patterns
Allan Huang
 
Weighted feed recommand
Weighted feed recommandWeighted feed recommand
Weighted feed recommand
Allan Huang
 
eSobi Site Initiation
eSobi Site InitiationeSobi Site Initiation
eSobi Site Initiation
Allan Huang
 
Architecture of eSobi club based on J2EE
Architecture of eSobi club based on J2EEArchitecture of eSobi club based on J2EE
Architecture of eSobi club based on J2EE
Allan Huang
 
J2EE Performance Monitor (Profiler)
J2EE Performance Monitor (Profiler)J2EE Performance Monitor (Profiler)
J2EE Performance Monitor (Profiler)
Allan Huang
 
Search is not only search
Search is not only searchSearch is not only search
Search is not only search
Allan Huang
 
Issue tracking workflow in web development and maintenance cycle
Issue tracking workflow in web development and maintenance cycleIssue tracking workflow in web development and maintenance cycle
Issue tracking workflow in web development and maintenance cycle
Allan Huang
 

Recently uploaded (20)

!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
Ranking Google
 
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdfProtect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
株式会社クライム
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
Solar-wind hybrid engery a system sustainable power
Solar-wind  hybrid engery a system sustainable powerSolar-wind  hybrid engery a system sustainable power
Solar-wind hybrid engery a system sustainable power
bhoomigowda12345
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
How I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetryHow I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetry
Cees Bos
 
Medical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk ScoringMedical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk Scoring
ICS
 
Download MathType Crack Version 2025???
Download MathType Crack  Version 2025???Download MathType Crack  Version 2025???
Download MathType Crack Version 2025???
Google
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Streamline Your Manufacturing Data. Strengthen Every Operation.
Streamline Your Manufacturing Data. Strengthen Every Operation.Streamline Your Manufacturing Data. Strengthen Every Operation.
Streamline Your Manufacturing Data. Strengthen Every Operation.
Aparavi
 
Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509
Fermin Galan
 
Maximizing ROI with Odoo Staff Augmentation A Smarter Way to Scale
Maximizing ROI with Odoo Staff Augmentation  A Smarter Way to ScaleMaximizing ROI with Odoo Staff Augmentation  A Smarter Way to Scale
Maximizing ROI with Odoo Staff Augmentation A Smarter Way to Scale
SatishKumar2651
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
Exchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv SoftwareExchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv Software
Shoviv Software
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
Meet the New Kid in the Sandbox - Integrating Visualization with Prometheus
Meet the New Kid in the Sandbox - Integrating Visualization with PrometheusMeet the New Kid in the Sandbox - Integrating Visualization with Prometheus
Meet the New Kid in the Sandbox - Integrating Visualization with Prometheus
Eric D. Schabell
 
sequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineeringsequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineering
aashrithakondapalli8
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
Ranking Google
 
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdfProtect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
株式会社クライム
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
Solar-wind hybrid engery a system sustainable power
Solar-wind  hybrid engery a system sustainable powerSolar-wind  hybrid engery a system sustainable power
Solar-wind hybrid engery a system sustainable power
bhoomigowda12345
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
How I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetryHow I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetry
Cees Bos
 
Medical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk ScoringMedical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk Scoring
ICS
 
Download MathType Crack Version 2025???
Download MathType Crack  Version 2025???Download MathType Crack  Version 2025???
Download MathType Crack Version 2025???
Google
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Streamline Your Manufacturing Data. Strengthen Every Operation.
Streamline Your Manufacturing Data. Strengthen Every Operation.Streamline Your Manufacturing Data. Strengthen Every Operation.
Streamline Your Manufacturing Data. Strengthen Every Operation.
Aparavi
 
Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509
Fermin Galan
 
Maximizing ROI with Odoo Staff Augmentation A Smarter Way to Scale
Maximizing ROI with Odoo Staff Augmentation  A Smarter Way to ScaleMaximizing ROI with Odoo Staff Augmentation  A Smarter Way to Scale
Maximizing ROI with Odoo Staff Augmentation A Smarter Way to Scale
SatishKumar2651
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
Exchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv SoftwareExchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv Software
Shoviv Software
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
Meet the New Kid in the Sandbox - Integrating Visualization with Prometheus
Meet the New Kid in the Sandbox - Integrating Visualization with PrometheusMeet the New Kid in the Sandbox - Integrating Visualization with Prometheus
Meet the New Kid in the Sandbox - Integrating Visualization with Prometheus
Eric D. Schabell
 
sequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineeringsequencediagrams.pptx software Engineering
sequencediagrams.pptx software Engineering
aashrithakondapalli8
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 

Build, logging, and unit test tools

  • 1. Build, Logging, and Unit Test Tools Allan Huang @ Delta DRC
  • 2. Agenda  Build Tool ◦ Maven  Logging Tool ◦ Log4J 2 and SLF4J  Unit Test Tool ◦ JUnit 4
  • 4. What is Maven?  Aspects of building software ◦ How software is built? ◦ What are its dependencies?  Convention over Configuration  Maven ◦ Software project management tool ◦ Build-automation tool  Manage project’s build, dependency and documentation
  • 6. Standard Directory Layout (1)  src/main ◦ Contains all of the code and resources needed for building the artifact. ◦ src/main/java  Contains the deliverable Java source code for the project. ◦ src/main/resources  Contains any configuration files, data files, or Java properties to include in the bundle. ◦ src/main/scripts  Contains some kinds of application usage scripts, e.g. windows batch script, Linux shell script. ◦ src/main/webapp  Contains your Java web application, if your project is a web application. It is the root directory of the web application.
  • 7. Standard Directory Layout (2)  src/test ◦ Contains all of the code and resources for running unit tests against the compiled artifact. ◦ src/test/java  Contains the testing Java source code (JUnit or TestNG test cases, for example) for the project. ◦ src/test/resources  Contains resources necessary for testing.  src/assembly ◦ Contains some assembly descriptors for creating distributions in the target directory.  target ◦ It is used to house all output of the build.  pom.xml ◦ The top level files descriptive of the project.
  • 8. Dependency Scope  Compile ◦ Compile dependencies are available in all class-paths of a project.  Provided ◦ Indicates you expect the JDK or a container to provide the dependency at runtime.  Runtime ◦ Indicates that the dependency is not required for compilation, but is for execution.  Test ◦ Indicates that the dependency is only available for the test compilation and execution phases.  System ◦ You have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.
  • 9. Build Lifecycle  Clean ◦ Remove all files generated by the previous build.  Default ◦ validate → compile → test → package → integration-test → verify → install → deploy  Site ◦ Generates the project's site documentation.
  • 10. Default Lifecycle (1)  Validate ◦ validate the project is correct and all necessary information is available.  Compile ◦ Compile the source code of the project.  Test ◦ Test the compiled source code using a suitable unit testing framework. ◦ These tests should not require the code be packaged or deployed.  Package ◦ Take the compiled code and package it in its distributable format, such as a JAR.
  • 11. Default Lifecycle (2)  Integration-test ◦ Process and deploy the package if necessary into an environment where integration tests can be run.  Verify ◦ Run any checks to verify the package is valid and meets quality criteria.  Install ◦ Install the package into the local repository, for use as a dependency in other projects locally.  Deploy ◦ Done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
  • 12. POM  Project Object Model (POM) ◦ Contains a complete description of how to build the current project. ◦ pom.xml  Effective POM  Parent/Super POM and Sub POM
  • 13. Repository Type  Local repository  Remote repository  Maven Central repository ◦ http://search.maven.o rg
  • 14. Build with Maven  Environment Setup ◦ Set JAVA_HOME ◦ Set M2_HOME ◦ Add M2_HOME/bin to System PATH ◦ Verify with command line  mvn –version  Local Repository Setting ◦ M2_HOME/conf/settings.xml  localRepository & proxies setting  Build projects with command line ◦ mvn (default goal)  Target ◦ Classes, Test-classes, Test reports, JAR, WAR, etc.
  • 15. Reference  Apache Maven  Maven Tutorial  Introduction to the Standard Directory Layout  Maven Directory Structure  Introduction to the Dependency Mechanism  Introduction to the Build Lifecycle  Maven in 5 Minutes  Maven - Environment Setup
  • 17. What is Log4J 2?  A fast and flexible framework for logging application debugging messages.  Logging behavior can be controlled by editing a configuration file, without touching the application binary.  Log4j 2 is an upgrade to Log4j.
  • 18. What is SLF4J?  Simple Logging Facade for Java ◦ Serves as a simple facade or abstraction for various logging frameworks allowing the end user to plug in the desired logging framework at deployment time.  Well-known logging frameworks ◦ Log4j 2, Log4j ◦ Logback ◦ Java Util Logging
  • 19. SLF4J bound to Log4J
  • 20. SLF4J, JDK Logging and Log4J 2
  • 21. Log Level  ERROR (be suited for Production environment) ◦ Something terribly wrong had happened, that must be investigated immediately.  e.g. Null pointer, Database unavailable, Mission critical.  WARN (be suited for Production environment) ◦ The process might be continued, but take extra caution.  e.g. Database connection lost, Socket reaching to its limit.  INFO (be suited for Test/QA environment) ◦ Important process has finished. Then quickly find out what the application is doing.  e.g. Server has been started, Incoming messages, Outgoing messages.  DEBUG (be suited for Development environment) ◦ It is used by the developers to debug the systems.  ALL, FATAL, TRACE, OFF levels are rarely used.
  • 22. SLF4J Common API  private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class);  void debug(String msg)  void debug(String format, Object... arguments)  void debug(String msg, Throwable t)  void info(String msg)  void info(String format, Object... arguments)  void info(String msg, Throwable t)  void warn(String msg)  void warn(String format, Object... arguments)  void warn(String msg, Throwable t)  void error(String msg)  void error(String format, Object... arguments)  void error(String msg, Throwable t)
  • 23. Log4J 2 Configuration (1)  log4j2.xml  Appenders ◦ Console Appender ◦ Rolling File Appender  OnStartup Triggering Policy  SizeBased Triggering Policy  TimeBased Triggering Policy  Loggers  Root Logger  Named Logger  Named Hierarchy
  • 25. Logging Tips (1)  Use the appropriate tools for the job ◦ log.debug("Found {} records matching filter: '{}'", records, filter);  Don’t forget, logging levels are there for you  Do you know what you are logging? ◦ log.debug("Processing request with id: {}", request.getId()); ◦ log.debug("Returning users: {}", users);  Avoid side effects ◦ try { log.trace("Id=" + request.getUser().getId() + " accesses " + manager.getPage().getUrl().toString()) } catch(NullPointerException e) { }
  • 26. Logging Tips (2)  Be concise and descriptive ◦ log.debug("Message processed"); log.debug(message.getJMSMessageID()); log.debug("Message with id '{}' processed", message.getJMSMessageID());  Tune your pattern in log4j2.xml  Log method arguments and return values  Watch out for external systems ◦ Communicates with an external system, consider logging every piece of data that comes out from your application and gets in.
  • 27. Logging Tips (3)  Log exceptions properly  Logs easy to read, easy to parse
  • 28. Reference  Frequently Asked Questions about SLF4J  FAQ about Log4j 2  SLF4J Logger API  Log4J 2 Appenders  log4j2 xml configuration example  10 Tips for Proper Application Logging  Logging Anti-Patterns  Logging in Java with slf4j
  • 30. What is JUnit 4?  A simple unit testing framework to write repeatable tests for Java.  Test-Driven Development (TDD) ◦ Test-first Development ◦ High Code Coverage  A static main method vs. Unit test cases  JUnit 4 is an upgrade to JUnit 3.
  • 34. JUnit 4 Assert method  assertArrayEquals(message, expecteds, actuals) ◦ Tests whether two arrays are equal to each other.  assertEquals(message, expected, actual) ◦ Compares two objects for equality, using their equals() method.  assertTrue(message, condition) & assertFalse(message, condition) ◦ Tests a single variable to see if its value is either true, or false.  assertNull(message, object) & assertNotNull(message, object) ◦ Tests a single variable to see if it is null or not null.  assertSame(message, expected, actual) & assertNotSame(message, unexpected, actual) ◦ Tests if two object references point to the same object or not.  assertThat(message, actual, matcher) ◦ Compares an object to an org.hamcrest.Matcher to see if the given object matches whatever the Matcher requires it to match.  fail(message) ◦ Fails a test with the given message.
  • 35. Reference  JUnit  Junit 3 vs Junit 4 Comparison  Assert Methods  Assert (JUnit API)
  • 36. Q & A
  翻译: