apps unit testing
TRANSCRIPT
-
7/25/2019 Apps Unit Testing
1/21
Unit [email protected]
Australian Development Centre
Brisbane, Australia
mailto:[email protected]:[email protected] -
7/25/2019 Apps Unit Testing
2/21
Aims
Unit Testing vs Traditional Testing
Benefts o Unit Testing
Introduction to Unit !using "Unit#rame$orks
Advanced Unit Testing %trategies
-
7/25/2019 Apps Unit Testing
3/21
Traditional Testing
Test t&e s'stem as a$&ole
Individual
components rarel'tested
(rrors go undetected
Isolation o errors
di)cult to trackdo$n
-
7/25/2019 Apps Unit Testing
4/21
Traditional Testing Strategies
*rint %tatements
Use o Debugger
Debugger (pressionsTest %cripts
-
7/25/2019 Apps Unit Testing
5/21
Unit Testing
(ac& part testedindividuall'
All components
tested at least once (rrors picked up
earlier
%cope is smaller,
easier to f errors
-
7/25/2019 Apps Unit Testing
6/21
Unit Testing Ideals
Isolatable
+epeatable
Automatable (as' to rite
-
7/25/2019 Apps Unit Testing
7/21
-
7/25/2019 Apps Unit Testing
8/21
Unit Tests
%imple %tandalone Classes
ig& /evel Classes
Database based Classes Integrated -rame$ork Classes
-
7/25/2019 Apps Unit Testing
9/21
JUnit (www.junit.org)
"ava0based unittesting rame$ork
(legantl' simple
(as' to $rite unittests
(as' to manage unittests
1pen source 2 -ree3
4ature -rame$ork
De acto 5avastandard
Ant integration 6eneric testing
rame$ork
-
7/25/2019 Apps Unit Testing
10/21
JUnit Is Not Pere!t
6UI testing7 4arat&on 4an, in+unner
("B Components7 ttpUnit, Cactus
/imited +eporting mec&anism7 Artima
Time to set upTesting o non05ava ob5ects di)cult
-
7/25/2019 Apps Unit Testing
11/21
"ey #on!e$ts in JUnit
Test interace
Assert
TestCase7 assertTrue7 assert(8uals7 ail
Test%uiteTestDecorator9Test%etup
-ailures vs (rrors
run(TestResult)
TestCasesetUp()
tearDown()
TestSuiterun(TestResult)
Assert
-
7/25/2019 Apps Unit Testing
12/21
JUnit is %asy
public void testInvalidPersonName()
{
person.setFirstName(null);
person.setLastName(Smith);
tr! {
personService.createPerson(person);
"ail(#n invalid person name should be thro$n);
% catch (InvalidPersonName ipn) {
&& 'ception epected
%
%
-
7/25/2019 Apps Unit Testing
13/21
Writing a Unit Test
:. Create a class to &old t&e unit tests
;. Initialise ob5ects !setUp!# met&od#
. Call operations on t&e ob5ects t&at are
being unit tested
?. %tate assertions9ailures epected
. Clean up !tearDo$n!# met&od#
. (ecute t&e unit test
-
7/25/2019 Apps Unit Testing
14/21
JUnit &est Pra!ti!es
%etting up unit tests
+unning unit tests
riting unit tests
-
7/25/2019 Apps Unit Testing
15/21
Setting u$ Unit Tests
ctb src oracle apps ctb test oracle
apps ctb
public class Somelass
{ ..
public void some*ethod() { .. %
..%
public class Somelass+est{ public void testSome*ethod() { .. %%
-
7/25/2019 Apps Unit Testing
16/21
'unning Unit Tests
Defne standard Ant targets +un unit tests automaticall' and
continuousl'
Implement code coverage tools
Line notexecuted
Executed line
u!ber o" ti!esexecuted
-
7/25/2019 Apps Unit Testing
17/21
uality o Unit Tests
umber o Unit Tests
Code Coverage
-
7/25/2019 Apps Unit Testing
18/21
Writing Unit Tests
Avoid setup in constructor
Defne tests correctl'
4inimise side0eects ounit tests
/everage "units assertionsand ailures to t&eir ullest
Eeep tests small and ast
Automate all processes
rite eective eception&andling code
Add a test case or ever'bug eposed
+eactor, reactor, reactor
-
7/25/2019 Apps Unit Testing
19/21
Adan!ed Unit Testing
4ock 1b5ects
&at to Test and o$ 4uc& to Test7 Bugs
7 e$ -unctionalit'
1ptimiFe +unning Time
Code Coverage
(nvironment 4anagement7 Continuous Integration7 /ocal and remote development
-
7/25/2019 Apps Unit Testing
20/21
#on!lusion
Unit testing adds enormous value tosot$are development
"Unit makes testing 5ava programs eas'
Advanced Unit Testing Concepts
-
7/25/2019 Apps Unit Testing
21/21
uestions?