4 maven junit

Honnix Liang
Honnix LiangEricsson
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
1 de 43

Recomendados

Note - Apache Maven Intro por
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Introboyw165
2.6K visualizações15 slides
Introduction in Apache Maven2 por
Introduction in Apache Maven2Introduction in Apache Maven2
Introduction in Apache Maven2Heiko Scherrer
870 visualizações40 slides
Apache maven 2 overview por
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overviewReturn on Intelligence
1.8K visualizações37 slides
Maven for Dummies por
Maven for DummiesMaven for Dummies
Maven for DummiesTomer Gabel
6.3K visualizações9 slides
Maven por
MavenMaven
Mavenfeng lee
1.8K visualizações33 slides
Liferay maven sdk por
Liferay maven sdkLiferay maven sdk
Liferay maven sdkMika Koivisto
3.2K visualizações20 slides

Mais conteúdo relacionado

Mais procurados

Maven por
Maven Maven
Maven Khan625
905 visualizações9 slides
Apache Maven por
Apache MavenApache Maven
Apache MavenRahul Tanwani
2.1K visualizações35 slides
Introduction to maven por
Introduction to mavenIntroduction to maven
Introduction to mavenManos Georgopoulos
1.2K visualizações24 slides
Maven por
MavenMaven
MavenChris Roeder
2.3K visualizações34 slides
Enterprise Maven Repository BOF por
Enterprise Maven Repository BOFEnterprise Maven Repository BOF
Enterprise Maven Repository BOFMax Andersen
823 visualizações83 slides
Lorraine JUG (1st June, 2010) - Maven por
Lorraine JUG (1st June, 2010) - MavenLorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - MavenArnaud Héritier
1.1K visualizações141 slides

Mais procurados(20)

Maven por Khan625
Maven Maven
Maven
Khan625905 visualizações
Apache Maven por Rahul Tanwani
Apache MavenApache Maven
Apache Maven
Rahul Tanwani2.1K visualizações
Introduction to maven por Manos Georgopoulos
Introduction to mavenIntroduction to maven
Introduction to maven
Manos Georgopoulos1.2K visualizações
Maven por Chris Roeder
MavenMaven
Maven
Chris Roeder2.3K visualizações
Enterprise Maven Repository BOF por Max Andersen
Enterprise Maven Repository BOFEnterprise Maven Repository BOF
Enterprise Maven Repository BOF
Max Andersen823 visualizações
Lorraine JUG (1st June, 2010) - Maven por Arnaud Héritier
Lorraine JUG (1st June, 2010) - MavenLorraine JUG (1st June, 2010) - Maven
Lorraine JUG (1st June, 2010) - Maven
Arnaud Héritier1.1K visualizações
Apache Maven - eXo TN presentation por Arnaud Héritier
Apache Maven - eXo TN presentationApache Maven - eXo TN presentation
Apache Maven - eXo TN presentation
Arnaud Héritier915 visualizações
Introduction to Maven por Sperasoft
Introduction to MavenIntroduction to Maven
Introduction to Maven
Sperasoft946 visualizações
An introduction to Maven por Joao Pereira
An introduction to MavenAn introduction to Maven
An introduction to Maven
Joao Pereira7.9K visualizações
Maven Introduction por Sandeep Chawla
Maven IntroductionMaven Introduction
Maven Introduction
Sandeep Chawla21.1K visualizações
Continuous Deployment Pipeline with maven por Alan Parkinson
Continuous Deployment Pipeline with mavenContinuous Deployment Pipeline with maven
Continuous Deployment Pipeline with maven
Alan Parkinson7.6K visualizações
Maven ppt por natashasweety7
Maven pptMaven ppt
Maven ppt
natashasweety74.6K visualizações
Introduction tomaven por Manav Prasad
Introduction tomavenIntroduction tomaven
Introduction tomaven
Manav Prasad236 visualizações
Maven advanced por Smita Prasad
Maven advancedMaven advanced
Maven advanced
Smita Prasad970 visualizações
Gradle - Build system evolved por Bhagwat Kumar
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
Bhagwat Kumar921 visualizações
Apache Maven for SoftServe IT Academy por Volodymyr Ostapiv
Apache Maven for SoftServe IT AcademyApache Maven for SoftServe IT Academy
Apache Maven for SoftServe IT Academy
Volodymyr Ostapiv3K visualizações
JBoss Enterprise Maven Repository por Max Andersen
JBoss Enterprise Maven RepositoryJBoss Enterprise Maven Repository
JBoss Enterprise Maven Repository
Max Andersen1.9K visualizações
Maven Overview por FastConnect
Maven OverviewMaven Overview
Maven Overview
FastConnect8.5K visualizações
Gradle - time for another build por Igor Khotin
Gradle - time for another buildGradle - time for another build
Gradle - time for another build
Igor Khotin2.4K visualizações

Similar a 4 maven junit

Intelligent Projects with Maven - DevFest Istanbul por
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulMert Çalışkan
1.3K visualizações58 slides
Maven por
MavenMaven
MavenShraddha
416 visualizações24 slides
How maven makes your development group look like a bunch of professionals. por
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
945 visualizações24 slides
Learning Maven by Example por
Learning Maven by ExampleLearning Maven by Example
Learning Maven by ExampleHsi-Kai Wang
1.6K visualizações42 slides
Intro to Maven.ppt por
Intro to Maven.pptIntro to Maven.ppt
Intro to Maven.pptMohammadSamiuddin12
4 visualizações41 slides
Maven Basics - Explained por
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - ExplainedSmita Prasad
1.1K visualizações46 slides

Similar a 4 maven junit(20)

Intelligent Projects with Maven - DevFest Istanbul por Mert Çalışkan
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
Mert Çalışkan1.3K visualizações
Maven por Shraddha
MavenMaven
Maven
Shraddha416 visualizações
How maven makes your development group look like a bunch of professionals. por Fazreil Amreen Abdul Jalil
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 Jalil945 visualizações
Learning Maven by Example por Hsi-Kai Wang
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
Hsi-Kai Wang1.6K visualizações
Maven Basics - Explained por Smita Prasad
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
Smita Prasad1.1K visualizações
BMO - Intelligent Projects with Maven por Mert Çalışkan
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
Mert Çalışkan1.6K visualizações
S/W Design and Modularity using Maven por Scheidt & Bachmann
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
Scheidt & Bachmann2.9K visualizações
Introduction to Maven por Mindfire Solutions
Introduction to MavenIntroduction to Maven
Introduction to Maven
Mindfire Solutions955 visualizações
(Re)-Introduction to Maven por Eric Wyles
(Re)-Introduction to Maven(Re)-Introduction to Maven
(Re)-Introduction to Maven
Eric Wyles127 visualizações
Developing Liferay Plugins with Maven por Mika Koivisto
Developing Liferay Plugins with MavenDeveloping Liferay Plugins with Maven
Developing Liferay Plugins with Maven
Mika Koivisto11.7K visualizações
Ci jenkins maven svn por Ankur Goyal
Ci jenkins maven svnCi jenkins maven svn
Ci jenkins maven svn
Ankur Goyal2.2K visualizações
Embrace Maven por Guy Marom
Embrace MavenEmbrace Maven
Embrace Maven
Guy Marom213 visualizações
Maven basic concept por Ming-Sian Lin
Maven basic conceptMaven basic concept
Maven basic concept
Ming-Sian Lin843 visualizações
Java build tools por Sujit Kumar
Java build toolsJava build tools
Java build tools
Sujit Kumar79 visualizações
Java is evolving rapidly: Maven helps you staying on track por Arnaud Héritier
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
Arnaud Héritier822 visualizações
Mavennotes.pdf por AnkurSingh656748
Mavennotes.pdfMavennotes.pdf
Mavennotes.pdf
AnkurSingh6567489 visualizações
Juggling Java EE with Enterprise Apache Maven por elliando dias
Juggling Java EE with Enterprise Apache MavenJuggling Java EE with Enterprise Apache Maven
Juggling Java EE with Enterprise Apache Maven
elliando dias614 visualizações
Introduction to maven, its configuration, lifecycle and relationship to JS world por Dmitry Bakaleinik
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
Dmitry Bakaleinik691 visualizações
Session 2 por gayathiry
Session 2Session 2
Session 2
gayathiry167 visualizações

Último

PRODUCT LISTING.pptx por
PRODUCT LISTING.pptxPRODUCT LISTING.pptx
PRODUCT LISTING.pptxangelicacueva6
13 visualizações1 slide
SAP Automation Using Bar Code and FIORI.pdf por
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdfVirendra Rai, PMP
22 visualizações38 slides
Scaling Knowledge Graph Architectures with AI por
Scaling Knowledge Graph Architectures with AIScaling Knowledge Graph Architectures with AI
Scaling Knowledge Graph Architectures with AIEnterprise Knowledge
28 visualizações15 slides
The Research Portal of Catalonia: Growing more (information) & more (services) por
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
79 visualizações25 slides
HTTP headers that make your website go faster - devs.gent November 2023 por
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023Thijs Feryn
21 visualizações151 slides
handbook for web 3 adoption.pdf por
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdfLiveplex
22 visualizações16 slides

Último(20)

PRODUCT LISTING.pptx por angelicacueva6
PRODUCT LISTING.pptxPRODUCT LISTING.pptx
PRODUCT LISTING.pptx
angelicacueva613 visualizações
SAP Automation Using Bar Code and FIORI.pdf por Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
Virendra Rai, PMP22 visualizações
Scaling Knowledge Graph Architectures with AI por Enterprise Knowledge
Scaling Knowledge Graph Architectures with AIScaling Knowledge Graph Architectures with AI
Scaling Knowledge Graph Architectures with AI
Enterprise Knowledge28 visualizações
HTTP headers that make your website go faster - devs.gent November 2023 por Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn21 visualizações
handbook for web 3 adoption.pdf por Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex22 visualizações
Empathic Computing: Delivering the Potential of the Metaverse por Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst476 visualizações
The details of description: Techniques, tips, and tangents on alternative tex... por BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada126 visualizações
Mini-Track: Challenges to Network Automation Adoption por Network Automation Forum
Mini-Track: Challenges to Network Automation AdoptionMini-Track: Challenges to Network Automation Adoption
Mini-Track: Challenges to Network Automation Adoption
Network Automation Forum12 visualizações
PharoJS - Zürich Smalltalk Group Meetup November 2023 por Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi126 visualizações
Democratising digital commerce in India-Report por Kapil Khandelwal (KK)
Democratising digital commerce in India-ReportDemocratising digital commerce in India-Report
Democratising digital commerce in India-Report
Kapil Khandelwal (KK)15 visualizações
Special_edition_innovator_2023.pdf por WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2217 visualizações
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... por Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker33 visualizações
Case Study Copenhagen Energy and Business Central.pdf por Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 visualizações
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors por sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 visualizações
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... por Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Jasper Oosterveld13 visualizações
Info Session November 2023.pdf por AleksandraKoprivica4
Info Session November 2023.pdfInfo Session November 2023.pdf
Info Session November 2023.pdf
AleksandraKoprivica411 visualizações
Voice Logger - Telephony Integration Solution at Aegis por Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma31 visualizações

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

Notas do Editor

  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