4 maven junit

1,481 views

Published on

a series of basic java training courses, this is the fourth one

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,481
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
34
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • 4 maven junit

    1. 1. Java Basic Training III. Maven & JUnit
    2. 2. Jump into Maven• Perfect Build• What is Maven• Core Concepts• Lifecycle and Plugin• Acknowledgement
    3. 3. Perfect Build
    4. 4. Perfect Build• Automatic
    5. 5. Perfect Build• Automatic• Platform independent
    6. 6. Perfect Build• Automatic• Platform independent• Bunch of reusable components
    7. 7. Perfect Build• Automatic• Platform independent• Bunch of reusable components• Standardized
    8. 8. Perfect Build• Automatic• Platform independent• Bunch of reusable components• Standardized• Reproducible
    9. 9. What is Maven• Build tool, same as make, ant clean compile ... package ...
    10. 10. Exercises• Create a Maven based project• Try clean, compile, package, install
    11. 11. What is Maven• Dependency management tool• With repository log4j:log4j:1.2.15c.e.m:web:7.0 org.apache.struts:structs-core:2.1.0 org.springframework:spring-core:2.5
    12. 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. 13. Exercises• Change default junit dependency to version 4• Add slf4j and logback as dependencies
    14. 14. What is Maven• Information aggregation
    15. 15. Exercises• Generate Maven site • as homework
    16. 16. What is Maven• Set of rules - Convention over Configuration
    17. 17. What is Maven• Set of rules - Convention over Configuration • pom.xml
    18. 18. What is Maven• Set of rules - Convention over Configuration • pom.xml • src/main/java • src/main/resources
    19. 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. 20. Core Concepts• Coordinate
    21. 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. 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. 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. 24. Core Concepts• Dependency • GAV • type • scope • optional • exclusions
    25. 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. 26. Core Concepts• Repository Layout • GAV• Repository Type upload • Local • Remote download • Central• Nexus
    27. 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. 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 updating7.0.0-SNAPSHOT 7.1.0-SNAPSHOT master • Used for intermedium version
    29. 29. Lifecycle and Plugin
    30. 30. Lifecycle and PluginPlugin internal bindingLifecycle Phase Plugin Goal Taskprocess-resource maven-resources-plugin:resources copy main resources file to output dircompile maven-compiler-plugin:compile compile main java code to output dirprocess-test-resource maven-resources-plugin:testResources copy test resource file to test output dirtest-compile maven-compiler-plugin:testCompile compile test java code to test output dirtest maven-surefire-plugin:test run testspackage maven-jar-plugin:jar pack the jar fileinstall maven-install-plugin:install install project output artifacts to local repodeploy maven-deploy-plugin:deploy deploy project output artifacts to remote repo
    31. 31. Acknowledgement• Most of the contents are from Juvens book• Youll 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. 32. Acknowledgement• Most of the contents are from Juvens book• Youll 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. 33. JUnit in Action• Why Unit Test• Go with Maven• The Calculator Case• Coverage• Guidelines
    34. 34. Why Unit Test http://www.agitar.com/solutions/why_unit_testing.html
    35. 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. 36. Go with Maven• Hands-on
    37. 37. The Calculator Case• @Before• @Test, expected, timeout• @BeforeClass• @After• @AfterClass
    38. 38. Coverage
    39. 39. Coverage• Coverage helps • Understand unit test quality • Understand Product quality • Pass QD5 in /// the company
    40. 40. Coverage• Coverage helps • Understand unit test quality • Understand Product quality • Pass QD5 in /// the company• Coverage types • Line • Branch • ...
    41. 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. 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. 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

    ×