sofware development environment
TRANSCRIPT
![Page 1: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/1.jpg)
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
![Page 2: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/2.jpg)
2
Agenda• Eclipse• Subversive• Log4j• JUnit• Checkstyle
![Page 3: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/3.jpg)
3
Esclipse
Presenter: Đặng Phúc Vinh
![Page 4: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/4.jpg)
4
Eclipse• What is eclipse?• Architecture• Java BuildPath• Debugging a Program• Install plugins (DEMO)
![Page 5: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/5.jpg)
5
What is Eclipse?
• Eclipse is an integrated development environment (IDE)
• Used to develop applications using the Java programming language and other programming languages
![Page 6: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/6.jpg)
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
![Page 7: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/7.jpg)
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
![Page 8: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/8.jpg)
8
Eclipse Architecture?
![Page 9: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/9.jpg)
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
![Page 10: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/10.jpg)
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.
![Page 11: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/11.jpg)
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
![Page 12: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/12.jpg)
12
Java Build Path
![Page 13: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/13.jpg)
13
Debugging
• Breakpoint is a position in code that make program pause to allow programmer reading memory data during the interuption.
![Page 14: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/14.jpg)
14
Debugging
• Set Break point:
![Page 15: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/15.jpg)
15
Debugging
• Call stack:
![Page 16: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/16.jpg)
16
Debugging
• Variables view:
![Page 17: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/17.jpg)
17
Debugging
• Run menu:
![Page 18: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/18.jpg)
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.
![Page 19: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/19.jpg)
19
Install plugin
• Help -> Marketplace -> Popular -> Subversive
![Page 20: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/20.jpg)
20
Install plugin
![Page 21: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/21.jpg)
21
Subversive
Presenter: Đặng Phúc Vinh
![Page 22: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/22.jpg)
22
Subversive• What is Subversive?• Version Control Terminologies• SVN Life Cycle• Demo
![Page 23: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/23.jpg)
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
![Page 24: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/24.jpg)
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
![Page 25: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/25.jpg)
25
Version Control Terminologies
• Trunk:• Is a directory using to store client code• Usually checked out by client to work
together
![Page 26: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/26.jpg)
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
![Page 27: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/27.jpg)
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
![Page 28: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/28.jpg)
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
![Page 29: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/29.jpg)
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
![Page 30: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/30.jpg)
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:
![Page 31: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/31.jpg)
31
SVN
DEMO
![Page 32: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/32.jpg)
32
Log4J
Presenter: Đặng Quang Hưng
![Page 33: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/33.jpg)
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.
![Page 34: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/34.jpg)
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.
![Page 35: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/35.jpg)
35
3. Main component
![Page 36: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/36.jpg)
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”.
![Page 37: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/37.jpg)
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();
![Page 38: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/38.jpg)
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.
![Page 39: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/39.jpg)
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.
![Page 40: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/40.jpg)
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.
![Page 41: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/41.jpg)
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.
![Page 42: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/42.jpg)
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.
![Page 43: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/43.jpg)
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.
![Page 44: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/44.jpg)
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.
![Page 45: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/45.jpg)
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>
![Page 46: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/46.jpg)
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>
![Page 47: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/47.jpg)
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>
![Page 48: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/48.jpg)
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.
![Page 49: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/49.jpg)
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.
![Page 50: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/50.jpg)
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
![Page 51: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/51.jpg)
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.
![Page 52: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/52.jpg)
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.
![Page 53: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/53.jpg)
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.
![Page 54: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/54.jpg)
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.
![Page 55: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/55.jpg)
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.
![Page 56: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/56.jpg)
56
Unit testing with JUnit
Presenter: Nguyễn Tiến Đức
![Page 57: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/57.jpg)
Software Development Cycle
![Page 58: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/58.jpg)
Test phases
![Page 59: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/59.jpg)
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
![Page 60: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/60.jpg)
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.
![Page 61: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/61.jpg)
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.
![Page 62: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/62.jpg)
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.
![Page 63: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/63.jpg)
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.
![Page 64: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/64.jpg)
64
Design of JUnit
![Page 65: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/65.jpg)
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
![Page 66: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/66.jpg)
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);}
![Page 67: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/67.jpg)
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)
![Page 68: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/68.jpg)
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;
}
![Page 69: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/69.jpg)
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;}
}
![Page 70: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/70.jpg)
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)
![Page 71: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/71.jpg)
71
Java code review with CheckStyle
Presenter: Nguyễn Thanh Tùng
![Page 72: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/72.jpg)
72
Agenda
1. Why need coding standard ?2. What is CheckStyle ?3. How to CheckStyle works ?4. Use CheckStyle with eclipse5. Demo
![Page 73: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/73.jpg)
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
![Page 74: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/74.jpg)
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
![Page 75: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/75.jpg)
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
![Page 76: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/76.jpg)
76
How to CheckStyle works ?
• CheckStyle supports add-ins for various Java IDE and Build tools, such as :– Eclipse– NetBeans– IntelliJ– Maven– Ant– …
![Page 77: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/77.jpg)
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
![Page 78: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/78.jpg)
78
Use CheckStyle with eclipse : Result
![Page 79: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/79.jpg)
79
Use CheckStyle with eclipse : Report
![Page 80: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/80.jpg)
80
Demo
![Page 81: Sofware development Environment](https://reader035.vdocuments.us/reader035/viewer/2022062522/5882fd5d1a28abe70d8b4cdd/html5/thumbnails/81.jpg)
81
Thanks for watching