SlideShare uma empresa Scribd logo
1 de 36
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

Mais conteúdo relacionado

Mais procurados

Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsCarol McDonald
 
Top 30 Node.js interview questions
Top 30 Node.js interview questionsTop 30 Node.js interview questions
Top 30 Node.js interview questionstechievarsity
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in androidRakesh Jha
 
Java Concurrency in Practice
Java Concurrency in PracticeJava Concurrency in Practice
Java Concurrency in PracticeAlina Dolgikh
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/MultitaskingSasha 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 2016Christian 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 managementxuehan 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 DevShuhei Shogen
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN StackNir Noy
 
Logging with Logback in Scala
Logging with Logback in ScalaLogging with Logback in Scala
Logging with Logback in ScalaKnoldus Inc.
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance TuningMinh Hoang
 
JProfiler8 @ OVIRT
JProfiler8 @ OVIRTJProfiler8 @ OVIRT
JProfiler8 @ OVIRTLiran Zelkha
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with javaHoang Nguyen
 

Mais procurados (20)

Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and Trends
 
De Java 8 a Java 17
De Java 8 a Java 17De Java 8 a Java 17
De Java 8 a Java 17
 
Top 30 Node.js interview questions
Top 30 Node.js interview questionsTop 30 Node.js interview questions
Top 30 Node.js interview questions
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in android
 
Java Concurrency in Practice
Java Concurrency in PracticeJava Concurrency in Practice
Java Concurrency in Practice
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/Multitasking
 
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
 
What's new in Java 11
What's new in Java 11What's new in Java 11
What's new in Java 11
 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
 
Wait for your fortune without Blocking!
Wait for your fortune without Blocking!Wait for your fortune without Blocking!
Wait for your fortune without Blocking!
 
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)
 
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...
 
[Java concurrency]01.thread management
[Java concurrency]01.thread management[Java concurrency]01.thread management
[Java concurrency]01.thread management
 
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
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
 
Logging with Logback in Scala
Logging with Logback in ScalaLogging with Logback in Scala
Logging with Logback in Scala
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
JAVA BYTE CODE
JAVA BYTE CODEJAVA BYTE CODE
JAVA BYTE CODE
 
JProfiler8 @ OVIRT
JProfiler8 @ OVIRTJProfiler8 @ OVIRT
JProfiler8 @ OVIRT
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 

Destaque

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 allavarapuknigh7
 
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 EraSadayuki 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 v1AFATous
 
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 allavarapuknigh7
 
Q921 log lec2 v1
Q921 log lec2 v1Q921 log lec2 v1
Q921 log lec2 v1AFATous
 
Basic well log interpretation
Basic well log interpretationBasic well log interpretation
Basic well log interpretationShahnawaz Mustafa
 
Well logging analysis: methods and interpretation
Well logging analysis: methods and interpretationWell logging analysis: methods and interpretation
Well logging analysis: methods and interpretationCristiano Ascolani
 
registro de pozoz
registro de pozozregistro de pozoz
registro de pozozopulento22
 

Destaque (11)

Well logging
Well loggingWell logging
Well logging
 
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
 
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
 
REGISTROS PLT GRUPO H2
REGISTROS PLT GRUPO H2 REGISTROS PLT GRUPO H2
REGISTROS PLT GRUPO H2
 
Registro de Producción (PLT)
Registro de Producción (PLT)Registro de Producción (PLT)
Registro de Producción (PLT)
 
Q921 log lec3 v1
Q921 log lec3 v1Q921 log lec3 v1
Q921 log lec3 v1
 
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
 
Q921 log lec2 v1
Q921 log lec2 v1Q921 log lec2 v1
Q921 log lec2 v1
 
Basic well log interpretation
Basic well log interpretationBasic well log interpretation
Basic well log interpretation
 
Well logging analysis: methods and interpretation
Well logging analysis: methods and interpretationWell logging analysis: methods and interpretation
Well logging analysis: methods and interpretation
 
registro de pozoz
registro de pozozregistro de pozoz
registro de pozoz
 

Semelhante a Build, logging, and unit test tools

Comparative Development Methodologies
Comparative Development MethodologiesComparative Development Methodologies
Comparative Development Methodologieselliando 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 applicationsOrtus Solutions, Corp
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCFAKHRUN 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 3rdprat0ham
 
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
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxMurugesh33
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxMurugesh33
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC frameworkMohit Gupta
 
Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introductionSergii Fesenko
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introductionjyoti_lakhani
 

Semelhante a Build, logging, and unit test tools (20)

Selenium Training in Chennai
Selenium Training in ChennaiSelenium Training in Chennai
Selenium Training in Chennai
 
Comparative Development Methodologies
Comparative Development MethodologiesComparative Development Methodologies
Comparative Development Methodologies
 
Basic Java I
Basic Java IBasic Java I
Basic Java I
 
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)
 
Introduction java programming
Introduction java programmingIntroduction java programming
Introduction java programming
 
Java JDK.docx
Java JDK.docxJava JDK.docx
Java JDK.docx
 
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
 
Automation using ibm rft
Automation using ibm rftAutomation using ibm rft
Automation using ibm rft
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
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
 
java slides
java slidesjava slides
java slides
 
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...
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
Cypress Testing.pptx
Cypress Testing.pptxCypress Testing.pptx
Cypress Testing.pptx
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
 
Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introduction
 
Java Logging
Java LoggingJava Logging
Java Logging
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 

Mais de Allan Huang

Netty 4-based RPC System Development
Netty 4-based RPC System DevelopmentNetty 4-based RPC System Development
Netty 4-based RPC System DevelopmentAllan Huang
 
eSobi Website Multilayered Architecture
eSobi Website Multilayered ArchitectureeSobi Website Multilayered Architecture
eSobi Website Multilayered ArchitectureAllan Huang
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New EvolutionAllan Huang
 
JQuery New Evolution
JQuery New EvolutionJQuery New Evolution
JQuery New EvolutionAllan Huang
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignAllan Huang
 
Boilerpipe Integration And Improvement
Boilerpipe Integration And ImprovementBoilerpipe Integration And Improvement
Boilerpipe Integration And ImprovementAllan 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 PhoneGapAllan Huang
 
HTML5 Multithreading
HTML5 MultithreadingHTML5 Multithreading
HTML5 MultithreadingAllan Huang
 
HTML5 Offline Web Application
HTML5 Offline Web ApplicationHTML5 Offline Web Application
HTML5 Offline Web ApplicationAllan Huang
 
HTML5 Data Storage
HTML5 Data StorageHTML5 Data Storage
HTML5 Data StorageAllan Huang
 
Java Script Patterns
Java Script PatternsJava Script Patterns
Java Script PatternsAllan Huang
 
Weighted feed recommand
Weighted feed recommandWeighted feed recommand
Weighted feed recommandAllan Huang
 
eSobi Site Initiation
eSobi Site InitiationeSobi Site Initiation
eSobi Site InitiationAllan 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 J2EEAllan 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 searchAllan 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 cycleAllan Huang
 

Mais de Allan Huang (20)

Drools
DroolsDrools
Drools
 
Netty 4-based RPC System Development
Netty 4-based RPC System DevelopmentNetty 4-based RPC System Development
Netty 4-based RPC System Development
 
eSobi Website Multilayered Architecture
eSobi Website Multilayered ArchitectureeSobi Website Multilayered Architecture
eSobi Website Multilayered Architecture
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New Evolution
 
JQuery New Evolution
JQuery New EvolutionJQuery New Evolution
JQuery New Evolution
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Boilerpipe Integration And Improvement
Boilerpipe Integration And ImprovementBoilerpipe Integration And Improvement
Boilerpipe Integration And Improvement
 
YQL Case Study
YQL Case StudyYQL Case Study
YQL Case Study
 
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
 
HTML5 Multithreading
HTML5 MultithreadingHTML5 Multithreading
HTML5 Multithreading
 
HTML5 Offline Web Application
HTML5 Offline Web ApplicationHTML5 Offline Web Application
HTML5 Offline Web Application
 
HTML5 Data Storage
HTML5 Data StorageHTML5 Data Storage
HTML5 Data Storage
 
Java Script Patterns
Java Script PatternsJava Script Patterns
Java Script Patterns
 
Weighted feed recommand
Weighted feed recommandWeighted feed recommand
Weighted feed recommand
 
Web Crawler
Web CrawlerWeb Crawler
Web Crawler
 
eSobi Site Initiation
eSobi Site InitiationeSobi Site Initiation
eSobi Site Initiation
 
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
 
J2EE Performance Monitor (Profiler)
J2EE Performance Monitor (Profiler)J2EE Performance Monitor (Profiler)
J2EE Performance Monitor (Profiler)
 
Search is not only search
Search is not only searchSearch is not only search
Search is not only search
 
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
 

Último

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 

Último (20)

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 

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