Download Introduction to Eclipse

Document related concepts
no text concepts found
Transcript
敏捷方法教材
Eclipse Usage
林廷原、王秉森
1
Environment
• Eclipse IDE for Java Developers
– Version: Indigo Service Release 2, 32bit
• JDK SE 1.7
• Plug-in: eUML2 (studio)
– Reverse engineering
– Free for use, but some functionalities are limited.
• It’s enough for our project.
2
Contents
•
•
•
•
•
Introduction to Eclipse
JUnit
Software engineering
Plug-in(UML reverse)
Practical skills
3
Contents
•
•
•
•
•
Introduction to Eclipse
JUnit
Software engineering
Plug-in(UML reverse)
Practical skills
4
Introduction to Eclipse
• About eclipse:
– Free.
– Easy to use.
– …(data on wiki)
Just Try!
5
Introduction to Eclipse(Cont.)
Perspective
6
Introduction to Eclipse(Cont.)
• Try click right mouse button.
– Convenient.
– Easy to find what you want.
7
Introduction to Eclipse(Cont.)
Recover perspective from mess
8
Introduction to Eclipse(Cont.)
• We sincerely suggest you use and be familiar
with this kind of tools.
– Benefits: efficient, Intuitive.
• Get used to debug with debugger.
9
Introduction to Eclipse(Cont.)
DEMO
10
Contents
•
•
•
•
•
Introduction to Eclipse
JUnit
Software engineering
Plug-in(UML reverse)
Practical skills
11
JUnit
• JUnit is used to implement unit tests in java.
– is a java framework written by Erich Gamma and
Kent Beck.
• JUnit: Java unit test framework.
• Note: There are suitable frameworks for other programming languages
such as C# (NUnit),JavaScript (JSUnit) …
•
A software framework is an abstraction in which software providing generic functionality can be
selectively changed by user code, thus providing application specific software. It is a collection of software
libraries providing a defined application programming interface (API). (from Wiki)
12
JUnit(Cont.)
Software
Object
(Unit)
Belong to a same class,
but these are different
objects.
13
JUnit(Cont.)
• Object is instance of Class.
• Usually, a class has a corresponding Unit test
class.
– JUnit test case is written in class.
• We are going to test a unit. (a small piece of
software)
– Class
• Methods, fields…
14
JUnit(Cont.)
• Test is not easy.
– Debugging a small unit is much easier than
debugging all system.
• Unit test is one of many test methods.
– It’s Important to agile method.
FYI: Nice perspective about unit test:
http://zishen.blogspot.com/2011/04/unit-test.html
15
JUnit(Cont.)
Values are not equal?
1+1=3??
NullException…
Without Unit test…
16
JUnit(Cont.)
How about this?
And… the last build has
some errors.
Which one is wrong?
Boss: Fix it!
17
JUnit(Cont.)
18
JUnit(Cont.)
• Why use unit test?
– Auto.
– Fast.
– Easy to do by programmer.
– Improve efficiency of teamwork.
– Guarantee the result to be correct after code
modification.
– Make you sure that the modifications in the code
will not break your system without your
knowledge.
19
JUnit(Cont.)
With Unit test
Much better…
20
JUnit(Cont.)
• JUnit 3.8 or Junit 4.0?
– Readability of JUnit 4.0 is better than JUnit 3.8.
– We suggest you use JUnit 4.0.
– Junit 3.8 uses naming conventions.
– Junit 4.0 uses annotation.
FYI: What is Annotation? http://djjchobits.iteye.com/blog/569000
21
JUnit 3.8
public class testFixture extends TestCase{
Calculate calculate = null;
public void setUp() throws Exception {calculate = new
Calculate();}
public void tearDown() throws Exception {calculate = null;}
public void testAdd()
{assertEquals(30,calculate.Addition(10,20)); }
public void testSub() {assertEquals(-10,
calculate.Subtraction(10,20));}
}
22
JUnit 3.8(Cont.)
public void testDivisionByZero() {
try {
calculate.division(1,0);
fail(“Did’t catch the expected
exception !");
}
catch (ArithmeticException success) {
assertNotNull(success.getMessage());
}
}
23
JUnit 4.0
public class testFixture {
Calculate calculate = null;
annotation
@Before
public void initialize() throws Exception {calculate = new Calculate();}
@After
public void cleanObject() throws Exception {calculate = null;}
@Test
public void Add() {assertEquals(30,calculate.Addition(10,20));}
@Test
public void Sub() {assertEquals(10,calculate.Subtraction(10,20));}
}
24
JUnit 4.0
public class testFixture {
Calculate calculate = null;
Must be public and void
@Before
public void initialize() throws Exception {calculate = new Calculate();}
@After
public void cleanObject() throws Exception {calculate = null;}
@Test
public void Add() {assertEquals(30,calculate.Addition(10,20));}
@Test
public void Sub() {assertEquals(10,calculate.Subtraction(10,20));}
}
25
JUnit 4.0(Cont.)
public class testFixture {
Calculate calculate = null;
Method to be run before test.(Initialization)
@Before
public void initialize() throws Exception {calculate = new Calculate();}
Method to be run after test.(clearing)
@After
public void cleanObject() throws Exception {calculate = null;}
Method to be run as test case.
@Test
public void Add() {assertEquals(30,calculate.Addition(10,20));}
2 test cases
@Test
public void Sub() {assertEquals(10,calculate.Subtraction(10,20));}
}
assertNotNull, assertTrue, assertXXXXX
26
JUnit 4.0(Cont.)
public class testFixture {
Calculate calculate = null;
execute sequence
1 4 @Before
public void initialize() throws Exception {calculate = new Calculate();}
3 6
@After
public void cleanObject() throws Exception {calculate = null;}
2
@Test
public void Add() {assertEquals(30,calculate.Addition(10,20));}
5
@Test
public void Sub() {assertEquals(10,calculate.Subtraction(10,20));}
}
27
JUnit 4.0(Cont.)
@Test(expected=ArithmeticException.class)
public void testDivByZero() {
calculate.division(1,0);
}
Test case with expected exception.
28
JUnit in Eclipse
29
JUnit in Eclipse(Cont.)
30
JUnit in Eclipse(Cont.)
31
JUnit in Eclipse(Cont.)
32
JUnit in Eclipse(Cont.)
33
JUnit in Eclipse(Cont.)
34
JUnit in Eclipse(Cont.)
DEMO
35
Contents
•
•
•
•
•
Introduction to Eclipse
JUnit
Software engineering
Plug-in(UML reverse)
Practical skills
36
Software engineering
• Many IDEs(e.g. eclipse) are closely related to
software engineering.
– Unit test.
– Refactor.
– Java’s comments: header can be turned into
javadoc if you follow the header’s format.
• Eclipse has many powerful plugins supporting
software engineering.
– Such as UML editor, reverse tool…
37
Software engineering(Cont.)
38
Software engineering(Cont.)
Javadoc
39
Software engineering(Cont.)
Javadoc of ArrayList
40
Software engineering(Cont.)
Comment
(green)
Source code of ArrayList
/*I am comment too*/
header
(blue)
41
Software engineering(Cont.)
We can generate our API doc too!
We need HTML tag
to typeset.
42
Software engineering(Cont.)
DEMO
43
Contents
•
•
•
•
•
Introduction to Eclipse
JUnit
Software engineering
Plug-in(UML reverse)
Practical skills
44
Plug-in(UML reverse)
• Advantage:
– Dynamic generate UML diagram.
– The diagram will absolutely match the source
code.
45
Plug-in(UML reverse)(Cont.)
• Plug-in: eUML2 (studio version)
• Webpage:
http://www.soyatec.com/euml2/installation/
46
Plug-in(UML reverse)(Cont.)
• How to install software?
– Online update (we use this one)
– Offline installation
47
Plug-in(UML reverse)(Cont.)
• Help -> Install New Software
48
Plug-in(UML reverse)(Cont.)
• Click add button
• Type : http://www.soyatec.com/update in Location Field
49
Plug-in(UML reverse)(Cont.)
50
Plug-in(UML reverse)(Cont.)
• How to use it ?
– right click on package > eUML2> Class diagram
editor…
51
Plug-in(UML reverse)(Cont.)
• Result:
so easy !
52
Plug-in(UML reverse)(Cont.)
DEMO
53
Contents
•
•
•
•
•
Introduction to Eclipse
JUnit
Software engineering
Plug-in(UML reverse)
Practical skills
54
Shortcut key
look up shortcut key table
Shortcut key can also be change by us.
55
Shortcut key(Cont.)
• Find/Replace
Ctrl + F
• Undo
Ctrl + Z
• Run project
Ctrl + F11
56
Shortcut key(Cont.)
• Find next item
Ctrl + K
• Find previous item
Ctrl + Shift + K
• Content Assist
Alt + /
• Automatic typesetting(Format code)
Ctrl + Shift + F
57
Shortcut key(Cont.)
• Delete a line of text
Ctrl + D
• Rename the selected element
Alt + Shift + R
58
Shortcut key(Cont.)
• Search for references to the selected element
in the workspace
Ctrl+Shift+G
59
Search
Ex: search “age”
Scenario 1 : I'm not sure what the attribute of “age” is.
Use file search
result
60
Search(Cont.)
Scenario 2 : I know “age” is a java method.
Use java search
as easy as pie
result:
61
Search(Cont.)
Scenario 3 : I know “age” is a primitive data type.
:
result :
62
Open java source code
• Setting :window > Preferences > Java > install JREs
63
Open java source code(Cont.)
64
Open java source code(Cont.)
Java doc. 檔案
•
65
Open java source code(Cont.)
• See the java document
move the mouse onto the class you want to see
66
Open java source code(Cont.)
• See the java source code(open declaration)
ctrl + click the class you are interested in
67
Practical skills
DEMO
68
The end
Q&A:
Any question?
69