1
SDENguyễn Tiến Đức – 11110033
Đặng Phúc Vinh – 11110159Đặng Quang Hưng – 11110058
Nguyễn Thanh Tùng – 11110155 GVHD: ThS. Nguyễn Trần Thi Văn
2
Agenda• Eclipse• Subversive• Log4j• JUnit• Checkstyle
3
Esclipse
Presenter: Đặng Phúc Vinh
4
Eclipse• What is eclipse?• Architecture• Java BuildPath• Debugging a Program• Install plugins (DEMO)
5
What is Eclipse?
• Eclipse is an integrated development environment (IDE)
• Used to develop applications using the Java programming language and other programming languages
6
Eclipse versionVersion Name Date Platform Version
Austin 21 June 2004 3.0
Bravo 28 June 2005 3.1
Callisto 30 June 2006 3.2
Europa 29 June 2007 3.3
Ganymede 25 June 2008 3.4
Galileo 24 June 2009 3.5
Helios 23 June 2010 3.6
7
Eclipse versionVersion Name Date Platform Version
Indigo 22 June 2011 3.7
Juno 27 June 2012 3.8 and 4.2
Kepler 26 June 2013 4.3
Luna 25 June 2014 4.4
Mars 24 June 2015 (planned)
4.5
8
Eclipse Architecture?
9
Eclipse Architecture
• Eclipse provides the Rich Client Platform (RCP) for developing general purpose applications
• Equinox OSGi – a standard bundling framework• Core platform – boot Eclipse
10
Eclipse Architecture
• Standard Widget Toolkit (SWT)• JFace: viewer classes to bring
model view controller programming to SWT, file buffers, text handling, text editors.
• Eclipse Workbench: views, editors, perspectives, wizards.
11
Java Build Path
• Used to complie Java project with it dependent classes• Code in source folders• Jars and classes associated with the project• Classes and libraries used in the project
• Java build path can be modified
12
Java Build Path
13
Debugging
• Breakpoint is a position in code that make program pause to allow programmer reading memory data during the interuption.
14
Debugging
• Set Break point:
15
Debugging
• Call stack:
16
Debugging
• Variables view:
17
Debugging
• Run menu:
18
DebuggingKey Description
F5 Executes the currently selected line and goes to the next line in your program. If the selected line is a method call the debugger steps into the associated code.
F6 F6 steps over the call, i.e. it executes a method without stepping into it in the debugger.
F7 F7 steps out to the caller of the currently executed method. This finishes the execution of the current method and returns to the caller of this method.
F8 F8 tells the Eclipse debugger to resume the execution of the program code until is reaches the next breakpoint or watchpoint.
19
Install plugin
• Help -> Marketplace -> Popular -> Subversive
20
Install plugin
21
Subversive
Presenter: Đặng Phúc Vinh
22
Subversive• What is Subversive?• Version Control Terminologies• SVN Life Cycle• Demo
23
What is Subversive?
• A plugin in Eclipse that helps software developers to work together and also maintains complete history of their work.
• Allow developers to work simultaneously• Do not overwrite each other’s changes• Maintain history of every version of everything
24
Version Control Terminologies
• The Repository:• Central place to store all client work• Repository stores files and history• Accessed over a network• Client can store/retrieve their changes
to/from repository• Storing changes, a client makes available
these changes to other people• Retrieving changes; a client takes other
people changes as a working copy
25
Version Control Terminologies
• Trunk:• Is a directory using to store client code• Usually checked out by client to work
together
26
Version Control Terminologies
• Tags:• Is used to store named snapshots of the
project• Allows to give descriptive and memorable
names to specific version• Ex:
• FIX_ADD_METHOD_ERROR is more memorable than
• Repository UUID: 7ceef8cb-3799-40dd-a067-c216ec2e5247
• Revision: 13
27
Version Control Terminologies
• Branches:• Used to make development process to fork
off into two different directions• Ex:
• Release version 5.0• Create a branch so that development of
6.0 features can be kept separate from 5.0 bug-fixes
28
Version Control Terminologies
• Working copy:• Repository is shared by all the team• Client can’t modify it directly• Client checkout working copy• Working copy is private workplace• Client can do their work within isolated from
the rest of the team
29
Version Control Terminologies
• Commit changes:• Storing changes from private workplace to
central server• Other developer can retrieve these changes
by updating their working copy• Commit is atomic operation
30
SVN Life Cycle
• Create repository: create a new repository• Checkout: create a working copy from the
repository• Update: update working copy• Perform changes: edit, remove…• Review changes: review your changes before
commit• Fix mistakes: undo modifications that have
been made to the working copy• Resolve conflicts:• Commit changes:
31
SVN
DEMO
32
Log4J
Presenter: Đặng Quang Hưng
33
1. Introduction
• Almost every large application includes its own logging or tracing API.
• In conformance with this rule, the E.U. SEMPER project decided to write its own tracing API. This was in early 1996. After countless enhancements, several incarnations and much work that API has evolved to become log4j, a popular logging package for Java.
34
2. Pros and Cons
• Inserting log statements into code is a low-tech method for debugging it. Debuggers are not always available or applicable. This is usually the case for multithreaded
applications and distributed applications at large.• Logging does have its drawbacks.
It can slow down an application. If too verbose, it can cause scrolling blindness.
35
3. Main component
36
4. Logger hierarchy
• The hierarchy is maintained in the relationship between LoggerConfig objects.
• A LoggerConfig is said to be ancestor of another LoggerConfig if its name followed by a dot is a prefix of the descendant logger name.
• Ex: the LoggerConfig named “com.foo” is a parent of the LoggerConfig named “com.foo.Bar”.
37
4. Logger hierarchy (cont)
• The root LoggerConfig resides at the top of the LoggerConfig hierarchy.
• Logger logger = LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
• Logger logger = LogManager.getRootLogger();
38
5. LoggerContext
• The LoggerContext acts as the anchor point for the Logging system.
• It is possible to have multiple active LoggerContexts in an application depending on the circumstances.
39
6. Configuration
Every LoggerContext has an active Configuration. The Configuration contains all the Appenders,
context-wide Filters, LoggerConfigs. And contains the reference to the
StrSubstitutor.• During reconfiguration two Configuration objects
will exist. Once all Loggers have been redirected to the new Configuration, the old Configuration will be stopped and discarded.
40
7. Logger
• Loggers are created by calling LogManager.getLogger()
• The Logger itself performs no direct actions. It simply has a name and is associated with a
LoggerConfig. It extends AbstractLogger and implements the
required methods.
41
7. Logger (cont) – Retrieve Loggers
• Calling the LogManager.getLogger() method with the same name will always return a reference to the exact same Logger object.
• Logger x = LogManager.getLogger("wombat");• Logger y = LogManager.getLogger("wombat"); x and y refer to exactly the same Logger object.
42
8. LoggerConfig
• LoggerConfig objects are created when Loggers are declared in the logging configuration. The LoggerConfig contains a set of Filters that
must allow the LogEvent to pass before it will be passed to any Appenders.
It contains references to the set of Appenders that should be used to process the event.
43
8. LoggerConfig - Log levels
• LoggerConfigs will be assigned a Log Level.• The set of built-in levels includes TRACE, DEBUG,
INFO, WARN, ERROR, and FATAL.
44
9. Appenders
• Appenders are responsible for delivering LogEvents to their destination.
• Appenders always have a name so that they can be referenced from Loggers.
45
9.1 ConsoleAppender
• ConsoleAppender writes its output to either System.err or System.out with System.err being the default target.
<Appenders> <Console name="STDOUT" target="SYSTEM_OUT"> <PatternLayout pattern="%m%n"/> </Console></Appenders>
46
9.2 FileAppender
• The FileAppender is an OutputStreamAppender that writes to the File named in the fileName parameter.
<Appenders> <File name="MyFile" fileName="logs/app.log"> <PatternLayout> <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> </PatternLayout> </File></Appenders>
47
9.3 AsyncAppender
• The AsyncAppender accepts references to other Appenders and causes LogEvents to be written to them on a separate Thread.
<File name="MyFile" fileName="logs/app.log"> <PatternLayout> <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> </PatternLayout></File><Async name="Async"> <AppenderRef ref="MyFile"/></Async>
48
10. Layout
• An Appender uses a Layout to format a LogEvent into a form that meets the needs of whatever will be consuming the log event.
49
10.1 JSONLayout
• Appends a series of JSON events as strings serialized as bytes.
Parameter Type Description
compact boolean If true, the appender does not use end-of-lines and indentation. Defaults to false.
complete boolean If true, the appender includes the JSON header and footer. Defaults to false.
locationInfo boolean If true, the appender includes the location information in the generated JSON. Defaults to false.
50
10.2 HTMLLayout
• The HTMLLayout generates an HTML page and adds each LogEvent to a row in a table.
Parameter Type Description
contentType String The value to assign to the Content-Type header. The default is "text/html"
locationInfo boolean If true, the filename and line number will be included in the HTML output. The default value is false
title String A String that will appear as the HTML title
51
10.3 PatternLayout
• A flexible layout configurable with pattern string.• The goal of this class is to format a LogEvent and
return the results.• The format of the result depends on the
conversion pattern.
52
10.3 PatternLayout (cont)
Pattern Description
c{precision}logger{precision}
Outputs the name of the logger that published the logging event.
C{precision}class{precision}
Outputs the fully qualified class name of the caller issuing the logging request
d{pattern}date{pattern}
Outputs the date of the logging event
m, msgmessage
Outputs the application supplied message associated with the logging event
n Outputs the platform dependent line separator character or characters.
53
11.1 TimeFilter
• The time filter can be used to restrict filter to only a certain portion of the day.
Parameter Type Description
start String A time in HH:mm:ss format
end String A time in HH:mm:ss format
onMatch String Action to take when the filter matches. May be ACCEPT, DENY or NEUTRAL. The default value is NEUTRAL.
onMismatch String Action to take when the filter does not match. May be ACCEPT, DENY or NEUTRAL. The default value is DENY.
54
11. Filters
• Filters allow Log Events to be evaluated to determine if or how they should be published.
• A Filter will be called on one of its filter methods and will return a Result, which is an Enum that has one of 3 values - ACCEPT, DENY or NEUTRAL.
55
11.2 RegexFilter
• The RegexFilter allows the formatted or unformatted message to be compared against a regular expression.
Parameter Type Description
regex String The regular expression
onMatch String Action to take when the filter matches. May be ACCEPT, DENY or NEUTRAL. The default value is NEUTRAL
onMissmatch String Action to take when the filter does not match. May be ACCEPT, DENY or NEUTRAL. The default value is DENY.
56
Unit testing with JUnit
Presenter: Nguyễn Tiến Đức
Software Development Cycle
Test phases
59
Why writes test?
http://blog.crisp.se/henrikkniberg/2010/03/16/1268757660000.html
Toyota’s Prius example
A defect found in the production phase is about 50 times more expensive than if it is found during prototyping. If the defect is found after production it will be about 1,000 – 10,000 times more expensive
60
What is Unit testing?
• A Unit Test is a procedure to validate a single Functionality of an application.
One Functionality One Unit Test
• Unit testing is very essential to every software company to give a quality product to their customers.
61
Junit – an introduction
• JUnit is a unit testing framework for the java programming language.
• It comes from the family of unit testing frameworks, collectively called xUnit, where ‘x’ stands for the programming language, e.g. CPPUnit, JSUnit, PHPUnit, PyUnit, RUnit etc.
Kent Beck and Erich Gamma originally wrote this framework for ‘smalltalk’, and it was called SUnit. Later it rippled into other languages.
62
Why choose Junit?
Of course there are many tools like JUnit, but none like it.
• JUnit is simple and easy to use. • JUnit has the widest IDE support, Eclipse, NetBeans,
IntelliJ IDEA...• JUnit is recognized by popular build tools like, ant,
maven etc.• And… it’s free.
63
Design of JUnit
junit.framework.TestCase is the abstract command class which you subclass into your Test Classes.
junit.framework.TestSuite is a composite of other tests, either TestCase or TestSuite.
64
Design of JUnit
65
What Junit does
• Junit runs a suite of tests and reports results• For each test in the test suite:
– Junit call setup(): create any object you may need for testing
– Junit call one test method: testing…– Junit call teardown(): remove any objects
you created if necesary
66
Write a test case
• Define a subclass of junit.framework.TestCasepublic class CalculatorTest extends TestCase {}
• Define one or more testXXX() methods that can perform the tests and assert expected results. public void testAddition () {
assertEquals (1, 1);}
67
Asserting expectations
• assertEquals (expected, actual) • assertEquals (message, expected, actual) • assertEquals (expected, actual, delta)• assertEquals (message, expected, actual, delta) • assertFalse ((message)condition) • Assert(Not)Null (object) • Assert(Not)Null (message, object) • Assert(Not)Same (expected, actual) • Assert(Not)Same (message, expected, actual) • assertTrue ((message), condition)
68
Write a test case
• Override setUp() method to perform initialization. It will be executed before each of the tests gets executed.
@Overrideprotected void setUp () {calc = new Calculator();
}
• Override tearDown() method to clean up. It will be executed after each of the tests gets executed.
@Overrideprotected void tearDown () {calc = null;
}
69
Write a test suite
• Test suilt means bundle a few unit test cases and run it togetherWrite a class with a static method suite() that creates a junit.framework.TestSuite containing all the Tests.
public class AllTests {public static Test suite() {TestSuite suite = new TestSuite();suite.addTestSuite(<test-1>.class);suite.addTestSuite(<test-2>.class);return suite;}
}
70
Junit 4.xFeature Junit 3.x Junit 4.x
Test case testXXX() method @Test
Run before each test method Override setUp() @Before
Run after each test method Override tearDown() @After
Run before the first test method in the current class is invoked
None @BeforeClass
Run after the all the test in current class have been run
None @AfterClass
Ignore test Comment or remove code
@igore
Expected exception Catch exception @Test (expected = Exception.class)
Timeout None @Test(timeout = 100)
71
Java code review with CheckStyle
Presenter: Nguyễn Thanh Tùng
72
Agenda
1. Why need coding standard ?2. What is CheckStyle ?3. How to CheckStyle works ?4. Use CheckStyle with eclipse5. Demo
73
Why need coding standard ?
• Make the code easier to understand• Easy to maintain and debug• Large companies often have their own styles to the projects
• Ex: Google style Java code : https://google-styleguide.googlecode.com/svn/trunk/javaguide.html
74
What is CheckStyle ?
• An open source development tool to help programmers write Java code that adheres to a coding standard.
• It automates the process of checking Java code to verify code following standard or not.
• Official web site : http://checkstyle.sourceforge.net/
• Current version 6.1
75
How to CheckStyle works ?
• CheckStyle is add-ins component to IDE/Build tool• Coding standard is user pre-defined, and embedded
in each XML file• CheckStyle will depend on XML file to parse code,
then generate checking result to
76
How to CheckStyle works ?
• CheckStyle supports add-ins for various Java IDE and Build tools, such as :– Eclipse– NetBeans– IntelliJ– Maven– Ant– …
77
Use CheckStyle with eclipse
Setup add-in to Eclipse:• Make Eclipse to automatically download and
update the library– Use Eclipse Marketplace
• Manually download library from the official site, and copy to Eclipse plug-ins folder
78
Use CheckStyle with eclipse : Result
79
Use CheckStyle with eclipse : Report
80
Demo
81
Thanks for watching
Top Related