SlideShare une entreprise Scribd logo
1  sur  43
Java Basic Training
     III. Maven & JUnit
Jump into Maven

•   Perfect Build

•   What is Maven

•   Core Concepts

•   Lifecycle and Plugin

•   Acknowledgement
Perfect Build
Perfect Build

• Automatic
Perfect Build

• Automatic
• Platform independent
Perfect Build

• Automatic
• Platform independent
• Bunch of reusable components
Perfect Build

• Automatic
• Platform independent
• Bunch of reusable components
• Standardized
Perfect Build

• Automatic
• Platform independent
• Bunch of reusable components
• Standardized
• Reproducible
What is Maven
• Build tool, same as make, ant


     clean   compile   ...   package   ...
Exercises


• Create a Maven based project
• Try clean, compile, package, install
What is Maven
• Dependency management tool
• With repository
                 log4j:log4j:1.2.15



c.e.m:web:7.0


                   org.apache.struts:structs-core:2.1.0


  org.springframework:spring-core:2.5
What is Maven
• Dependency management tool
• With repository

                                           log4j:log4j:1.2.15


                     Depends on   org.apache.struts:structs-core:2.1.0
    Repository
                                  org.springframework:spring-core:2.5

                                             c.e.m:web:7.0
Exercises


• Change default junit dependency to version
  4
• Add slf4j and logback as dependencies
What is Maven
• Information aggregation
Exercises


• Generate Maven site
 • as homework
What is Maven
• Set of rules - Convention over
  Configuration
What is Maven
• Set of rules - Convention over
  Configuration
 • pom.xml
What is Maven
• Set of rules - Convention over
  Configuration
 • pom.xml
 • src/main/java
 • src/main/resources
What is Maven
• Set of rules - Convention over
  Configuration
 • pom.xml
 • src/main/java
 • src/main/resources
 • src/test/java
 • src/test/resources
Core Concepts
•   Coordinate
Core Concepts
•   Coordinate
    •   groupId – derived from project name, rather than
        organization name
    •   artifactId – derived from module name, rather
        than project name
    •   version – project version
Core Concepts
•   Coordinate
    •   groupId – derived from project name, rather than
        organization name
    •   artifactId – derived from module name, rather
        than project name
    •   version – project version
    •   packaging – project packaging type, like jar
        (default)
Core Concepts
•   Coordinate
    •   groupId – derived from project name, rather than
        organization name
    •   artifactId – derived from module name, rather
        than project name
    •   version – project version
    •   packaging – project packaging type, like jar
        (default)
    •   classifier – additional artifacts, like -javadoc.jar
Core Concepts
•   Dependency

    •   GAV

    •   type

    •   scope

    •   optional

    •   exclusions
Core Concepts
•   Dependency

    •   GAV        <project>
                     …
                     <dependencies>


    •
                       <dependency>
        type             <groupId>log4j</groupId>
                         <artifactId>log4j</artifactId>
                         <version>1.2.15</version>
                       </dependency>

    •   scope
                       <dependency>
                         <groupId>junit</groupId>
                         <artifactId>junit</artifactId>
                         <version>3.8.1</version>


    •
                       </dependency>
        optional     </dependencies>
                     …
                   </project>



    •   exclusions
Core Concepts
•   Repository Layout

    •   GAV

•   Repository Type          upload



    •   Local

    •   Remote          download



    •   Central

•   Nexus
Core Concepts
•   Snapshot version
    •   7.0.0-SNAPSHOT
    •   7.0.0-20120214.221414-13


    •   > mvn clean install -U

    •   Update daily by default, -U to force updating


    •   Used for intermedium version
Core Concepts
 •    Snapshot version
     •   7.0.0-SNAPSHOT
                      7.0.0-pc1-SNAPSHOT


     •
                 7.0.0
         7.0.0-20120214.221414-13
                          7.0.0-pc2-SNAPSHOT



                         7.0.1-SNAPSHOT   7.0.1   7.0.2-SNAPSHOT

     •   > mvn clean install -U                    7.0.1-pc1-SNAPSHOT


     •   Update daily by default, -U to force updating
7.0.0-SNAPSHOT           7.1.0-SNAPSHOT                                 master




     •   Used for intermedium version
Lifecycle and Plugin
Lifecycle and Plugin
Plugin internal binding
Lifecycle Phase         Plugin Goal                            Task

process-resource        maven-resources-plugin:resources       copy main resources file to output dir


compile                 maven-compiler-plugin:compile          compile main java code to output dir


process-test-resource   maven-resources-plugin:testResources   copy test resource file to test output dir


test-compile            maven-compiler-plugin:testCompile      compile test java code to test output dir


test                    maven-surefire-plugin:test              run tests


package                 maven-jar-plugin:jar                   pack the jar file


install                 maven-install-plugin:install           install project output artifacts to local repo


deploy                  maven-deploy-plugin:deploy             deploy project output artifacts to remote repo
Acknowledgement
•   Most of the contents are
    from Juven's book

•   You'll have chance to go
    through the whole
    training session talking
    about Maven hold by
    Juven

           Juven Xu
          www.juvenxu.com
      juven.xu@outsofting.com
         twitter.com/juvenxu
         weibo.com/juvenxu
Acknowledgement
•   Most of the contents are
    from Juven's book

•   You'll have chance to go
    through the whole
    training session talking
    about Maven hold by
    Juven

           Juven Xu
          www.juvenxu.com
      juven.xu@outsofting.com
         twitter.com/juvenxu
         weibo.com/juvenxu
JUnit in Action

•   Why Unit Test

•   Go with Maven

•   The Calculator Case

•   Coverage

•   Guidelines
Why Unit Test




      http://www.agitar.com/solutions/why_unit_testing.html
Why Unit Test

• Be professional
• Find defects as early as possible
• Living description of how the unit works
• Insurance and confidence for refactoring
• A lot of pleasure
Go with Maven


• Hands-on
The Calculator Case

• @Before
• @Test, expected, timeout
• @BeforeClass
• @After
• @AfterClass
Coverage
Coverage
•   Coverage helps
    •   Understand unit test quality
    •   Understand Product quality

    •   Pass QD5 in /// the company
Coverage
•   Coverage helps
    •   Understand unit test quality
    •   Understand Product quality

    •   Pass QD5 in /// the company
•   Coverage types
    •   Line
    •   Branch
    •   ...
Coverage
•   Coverage helps
    •   Understand unit test quality
    •   Understand Product quality

    •   Pass QD5 in /// the company
•   Coverage types
    •   Line
    •   Branch
    •   ...
•   Coverage tools
    •   Cobertura
    •   Emma
    •   Clover (commercial)
Guidelines

•   http://geosoft.no/development/unittesting.html
    (GFWed)

•   http://www.mymindleaks.com/blog/article/junit-
    best-practices-how-to-write-good-junit-test-
    cases.html
Homework
• Convert AddressBook project to Maven
  based
• Add unit test
• Search and learn how to use Cobertura, and
  make sure unit test line coverage reaches
  85%
• Add necessary configuration and files to
  facilitate generating Maven site

Contenu connexe

Tendances

Continuous Deployment Pipeline with maven
Continuous Deployment Pipeline with mavenContinuous Deployment Pipeline with maven
Continuous Deployment Pipeline with maven
Alan Parkinson
 

Tendances (20)

Maven
Maven Maven
Maven
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
Maven
MavenMaven
Maven
 
Enterprise Maven Repository BOF
Enterprise Maven Repository BOFEnterprise Maven Repository BOF
Enterprise Maven Repository BOF
 
Lorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - MavenLorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - Maven
 
Apache Maven - eXo TN presentation
Apache Maven - eXo TN presentationApache Maven - eXo TN presentation
Apache Maven - eXo TN presentation
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Maven
MavenMaven
Maven
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Continuous Deployment Pipeline with maven
Continuous Deployment Pipeline with mavenContinuous Deployment Pipeline with maven
Continuous Deployment Pipeline with maven
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Introduction tomaven
Introduction tomavenIntroduction tomaven
Introduction tomaven
 
Maven advanced
Maven advancedMaven advanced
Maven advanced
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
 
Apache Maven for SoftServe IT Academy
Apache Maven for SoftServe IT AcademyApache Maven for SoftServe IT Academy
Apache Maven for SoftServe IT Academy
 
JBoss Enterprise Maven Repository
JBoss Enterprise Maven RepositoryJBoss Enterprise Maven Repository
JBoss Enterprise Maven Repository
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
Gradle - time for another build
Gradle - time for another buildGradle - time for another build
Gradle - time for another build
 

Similaire à 4 maven junit

How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.
Fazreil Amreen Abdul Jalil
 
Java build tools
Java build toolsJava build tools
Java build tools
Sujit Kumar
 
Juggling Java EE with Enterprise Apache Maven
Juggling Java EE with Enterprise Apache MavenJuggling Java EE with Enterprise Apache Maven
Juggling Java EE with Enterprise Apache Maven
elliando dias
 

Similaire à 4 maven junit (20)

Introduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsIntroduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOps
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Maven
MavenMaven
Maven
 
How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.How maven makes your development group look like a bunch of professionals.
How maven makes your development group look like a bunch of professionals.
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
 
Intro to Maven.ppt
Intro to Maven.pptIntro to Maven.ppt
Intro to Maven.ppt
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
(Re)-Introduction to Maven
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to Maven
 
Developing Liferay Plugins with Maven
Developing Liferay Plugins with MavenDeveloping Liferay Plugins with Maven
Developing Liferay Plugins with Maven
 
Ci jenkins maven svn
Ci jenkins maven svnCi jenkins maven svn
Ci jenkins maven svn
 
Embrace Maven
Embrace MavenEmbrace Maven
Embrace Maven
 
Maven basic concept
Maven basic conceptMaven basic concept
Maven basic concept
 
Java build tools
Java build toolsJava build tools
Java build tools
 
Java is evolving rapidly: Maven helps you staying on track
Java is evolving rapidly:  Maven helps you staying on trackJava is evolving rapidly:  Maven helps you staying on track
Java is evolving rapidly: Maven helps you staying on track
 
Mavennotes.pdf
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
 
Juggling Java EE with Enterprise Apache Maven
Juggling Java EE with Enterprise Apache MavenJuggling Java EE with Enterprise Apache Maven
Juggling Java EE with Enterprise Apache Maven
 
Introduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS world
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

4 maven junit

  • 1. Java Basic Training III. Maven & JUnit
  • 2. Jump into Maven • Perfect Build • What is Maven • Core Concepts • Lifecycle and Plugin • Acknowledgement
  • 5. Perfect Build • Automatic • Platform independent
  • 6. Perfect Build • Automatic • Platform independent • Bunch of reusable components
  • 7. Perfect Build • Automatic • Platform independent • Bunch of reusable components • Standardized
  • 8. Perfect Build • Automatic • Platform independent • Bunch of reusable components • Standardized • Reproducible
  • 9. What is Maven • Build tool, same as make, ant clean compile ... package ...
  • 10. Exercises • Create a Maven based project • Try clean, compile, package, install
  • 11. What is Maven • Dependency management tool • With repository log4j:log4j:1.2.15 c.e.m:web:7.0 org.apache.struts:structs-core:2.1.0 org.springframework:spring-core:2.5
  • 12. What is Maven • Dependency management tool • With repository log4j:log4j:1.2.15 Depends on org.apache.struts:structs-core:2.1.0 Repository org.springframework:spring-core:2.5 c.e.m:web:7.0
  • 13. Exercises • Change default junit dependency to version 4 • Add slf4j and logback as dependencies
  • 14. What is Maven • Information aggregation
  • 15. Exercises • Generate Maven site • as homework
  • 16. What is Maven • Set of rules - Convention over Configuration
  • 17. What is Maven • Set of rules - Convention over Configuration • pom.xml
  • 18. What is Maven • Set of rules - Convention over Configuration • pom.xml • src/main/java • src/main/resources
  • 19. What is Maven • Set of rules - Convention over Configuration • pom.xml • src/main/java • src/main/resources • src/test/java • src/test/resources
  • 20. Core Concepts • Coordinate
  • 21. Core Concepts • Coordinate • groupId – derived from project name, rather than organization name • artifactId – derived from module name, rather than project name • version – project version
  • 22. Core Concepts • Coordinate • groupId – derived from project name, rather than organization name • artifactId – derived from module name, rather than project name • version – project version • packaging – project packaging type, like jar (default)
  • 23. Core Concepts • Coordinate • groupId – derived from project name, rather than organization name • artifactId – derived from module name, rather than project name • version – project version • packaging – project packaging type, like jar (default) • classifier – additional artifacts, like -javadoc.jar
  • 24. Core Concepts • Dependency • GAV • type • scope • optional • exclusions
  • 25. Core Concepts • Dependency • GAV <project> … <dependencies> • <dependency> type <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.15</version> </dependency> • scope <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> • </dependency> optional </dependencies> … </project> • exclusions
  • 26. Core Concepts • Repository Layout • GAV • Repository Type upload • Local • Remote download • Central • Nexus
  • 27. Core Concepts • Snapshot version • 7.0.0-SNAPSHOT • 7.0.0-20120214.221414-13 • > mvn clean install -U • Update daily by default, -U to force updating • Used for intermedium version
  • 28. Core Concepts • Snapshot version • 7.0.0-SNAPSHOT 7.0.0-pc1-SNAPSHOT • 7.0.0 7.0.0-20120214.221414-13 7.0.0-pc2-SNAPSHOT 7.0.1-SNAPSHOT 7.0.1 7.0.2-SNAPSHOT • > mvn clean install -U 7.0.1-pc1-SNAPSHOT • Update daily by default, -U to force updating 7.0.0-SNAPSHOT 7.1.0-SNAPSHOT master • Used for intermedium version
  • 30. Lifecycle and Plugin Plugin internal binding Lifecycle Phase Plugin Goal Task process-resource maven-resources-plugin:resources copy main resources file to output dir compile maven-compiler-plugin:compile compile main java code to output dir process-test-resource maven-resources-plugin:testResources copy test resource file to test output dir test-compile maven-compiler-plugin:testCompile compile test java code to test output dir test maven-surefire-plugin:test run tests package maven-jar-plugin:jar pack the jar file install maven-install-plugin:install install project output artifacts to local repo deploy maven-deploy-plugin:deploy deploy project output artifacts to remote repo
  • 31. Acknowledgement • Most of the contents are from Juven's book • You'll have chance to go through the whole training session talking about Maven hold by Juven Juven Xu www.juvenxu.com juven.xu@outsofting.com twitter.com/juvenxu weibo.com/juvenxu
  • 32. Acknowledgement • Most of the contents are from Juven's book • You'll have chance to go through the whole training session talking about Maven hold by Juven Juven Xu www.juvenxu.com juven.xu@outsofting.com twitter.com/juvenxu weibo.com/juvenxu
  • 33. JUnit in Action • Why Unit Test • Go with Maven • The Calculator Case • Coverage • Guidelines
  • 34. Why Unit Test http://www.agitar.com/solutions/why_unit_testing.html
  • 35. Why Unit Test • Be professional • Find defects as early as possible • Living description of how the unit works • Insurance and confidence for refactoring • A lot of pleasure
  • 36. Go with Maven • Hands-on
  • 37. The Calculator Case • @Before • @Test, expected, timeout • @BeforeClass • @After • @AfterClass
  • 39. Coverage • Coverage helps • Understand unit test quality • Understand Product quality • Pass QD5 in /// the company
  • 40. Coverage • Coverage helps • Understand unit test quality • Understand Product quality • Pass QD5 in /// the company • Coverage types • Line • Branch • ...
  • 41. Coverage • Coverage helps • Understand unit test quality • Understand Product quality • Pass QD5 in /// the company • Coverage types • Line • Branch • ... • Coverage tools • Cobertura • Emma • Clover (commercial)
  • 42. Guidelines • http://geosoft.no/development/unittesting.html (GFWed) • http://www.mymindleaks.com/blog/article/junit- best-practices-how-to-write-good-junit-test- cases.html
  • 43. Homework • Convert AddressBook project to Maven based • Add unit test • Search and learn how to use Cobertura, and make sure unit test line coverage reaches 85% • Add necessary configuration and files to facilitate generating Maven site

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n