Upload
guo-albert
View
3.123
Download
0
Tags:
Embed Size (px)
Citation preview
Applied MyEclipse and JUnit to do Hibernate Code Gen and TestingAlbert Guo
Agenda
• High Level Picture
• Hibernate Code Generation
– Code Gen Process
– Generate DAO for the four tables
– Artifacts
– Spring Configuration File
– Sequence Diagram
• Apply JUnit to do DAOs Test
– JUnit Framework
– How to Test with JUnit?
– Simplified Workflow of Applying JUnit
– Testing Process
– Generate Unit Test Result via Ant
2
High Level Picture
3
Client Layer Business Layer Persistence Layer
Spring – IOC Container
Hibernate Session Mgt.
Business Service Classes
HibernateWindchill Workflow
Data Source / Connection Pool
ApplicationContext
DAO Classes
ApplicationContext.xml Hibernate Mapping files
Code Gen Process
4
including POJOs, DAOs, hibernate mapping files and Spring configuration file
Filled in connection info.
Add MS SQL driver
5
Save password, then you do not need to type in again
Click Test Driver to test database connection
6
If you connect to database successfully, then you can see this popup window
Generate DAO for the four tables
7
8
Select tables which we would like to do code gen.
Click Hibernate Reverse Engineering
9
Assign destination
Generate hibernate mapping file
Generate POJO
Generate Spring DAO
10
Select ID Generator
11
Artifacts
12
We had generated POJOs, hibernate mapping files, and DAOs
Spring Configuration File
13
Inject webSiteDataSource into sessionFactory
Spring Configuration File – cont.
14
Inject sessionFactory into each DAOs.
Sequence Diagram
15
Apply Junit to do DAOs Test
16
JUnit Framework
17
run()
<< interface >>Test
fName
setUp()runTest()tearDown()run()
TestCase
run()addTest()
TestSuite
*
TestResult
junit.framework
assertTrue()assertEquals()...
Assert
junit.textui.TestRunner junit.swingui.TestRunner
How to Test with JUnit?
18
junit
WipPortingDAO
TestCase
exercise1..*
TestRunner
run1..*WipPortingDAOTest
test1
test2
…
Simplified Workflow of Applying JUnit
19
Class files
Test CasesTest MethodsTest Suites
Test Runner
Testing Process
20
Overrides setUp() and/or tearDown()
Writes test methods, ex.test…()
Uses Assert.assert…()
Writes suite() and/or main()
Create Fixture via MyEclipse
21
Create Fixture via MyEclipse – cont.
22
Create Fixture via MyEclipse – cont.
23
Create Fixture via MyEclipse – cont.
24
Exercise & Verify
25
Exercise & Verify – cont.
26
Suit Management
27
Suit Management
28
Generate Unit Test Result via Ant
29
Build.xml
Generate Unit Test Result via Ant
30