JUnit 4

Sunil OS
Sunil OSCorporate Training and Placements
www.SunilOS.com 1
www.sunilos.com
www.raystec.com
JUnit 4
03/17/16
03/17/16 www.SunilOS.com 2
Introduction
JUnit is an open source Java testing framework
It is used to write and run repeatable tests by
Developers.
Testing done by JUnit is called Unit Testing.
JUnit was originally written by Erich Gamma and
Kent Beck.
Test A Class – AccountService
 Lets have a Class that
provides Account Services
 Here are methods to
perform account services.
o add
o delete
o update
o get
o list
o getBalance
03/17/16 www.SunilOS.com 3
AccountService
+add(dto)
+update(dto)
+delete(dto)
+get(id)
+list() : List
+getBalance() : double
AccountDTO
+accssor
+id
+number
+name
+type
+balance
Conventional Testing Approach
 Write test in the main method
 public class TestAccount {
o public static void main(String[] args) {
 AccountDTO dto = new AccountDTO();
 dto.setId(1);
 dto.setNumber("SB123456");
 dto.setName("sunRays Technologies");
 dto.setBalance(10000);
 AccountService.add(dto); //Test#1
 AccountService.update(dto); //Test#2
 AccountService.delete(dto); //Test#3
 dto = AccountService.get(1); //Test#4
o }
 }
03/17/16 www.SunilOS.com 4
Problem ?
 AccountService.add(dto); //Test#1
 AccountService.update(dto); //Test#2
 AccountService.delete(dto); //Test#3
 dto = AccountService.get(1); //Test#4
 Any exception on any Test will
terminate subsequent tests from the
execution.
 Say if Test#2 has exception then
Test#3 and Test#4 will not be
executed. If Test#1 has exception then
Test#2,#3, and #4 will not be executed.
03/17/16 www.SunilOS.com 5
Solution
JUnit Framework.
Prepare Test Programs.
Test program is called
Testcase.
One Model/Service class will
have one JUnit Testcase.
Testing is called Unit Testing.
03/17/16 www.SunilOS.com 6
What is Unit Testcase
A Unit Testcase is a test program to test a
Usecase functionality.
A Testcase tests the response of a single
method to a particular set of input.
Unit Testcases are written and run by
Developers.
03/17/16 www.SunilOS.com 7
What is JUnit
JUnit is an open source Java testing
framework
It is used to write and run repeatable tests
by Developers.
Testing done by JUnit is called Unit Testing.
JUnit was originally written by Erich Gamma
and Kent Beck.
03/17/16 www.SunilOS.com 8
Features of JUnit
Fail and Assertion methods to test expected
results.
Test suites to execute multiple test cases
together.
Graphical and textual test runners.
03/17/16 www.SunilOS.com 9
Version 4.0
Current version is 4.x.
Supports Annotations.
03/17/16 www.SunilOS.com 10
What is regression testing
When you test new functionality along with
old functionality, is called regression testing.
Suppose you recently have developed
fundTransfer() method, when you test
openAccount(), deposit() and
withdraw() methods along with newly
created fundTransfer() method then it is
called regression testing.
03/17/16 www.SunilOS.com 11
Add testcase
 public class AccountServiceTestcase {
o @Test
o public void testAdd() {
 AccountDTO dto = new AccountDTO();
 dto.setId(1);
 dto.setNumber("SB123456");
 AccountService.add(dto);
 dto = AccountService.get(1);
 // If DTO is null then record is not added and testcase is fail
 if(dto == null){
 fail("Account is NOT added");
 }
o }
 }
03/17/16 www.SunilOS.com 12
Add testcase assert
 public class AccountServiceTestcase {
o @Test
o public void testAdd() {
 AccountDTO dto = new AccountDTO();
 dto.setId(1);
 dto.setNumber("SB123456");
 AccountService.add(dto);
 dto = AccountService.get(1);
 // If DTO is null then record is not added and testcase is fail
 assertNull("Account is NOT deleted", dto);
o }
 }
03/17/16 www.SunilOS.com 13
Delete testcase assert
 public class AccountServiceTestcase {
o @Test
o public void testDelete() {
 AccountDTO dto = new AccountDTO();
 dto.setId(1);
 AccountService.delete(dto);
 dto = AccountService.get(1);
 // If DTO is NOT null then record is not deleted and testcase is fail
 assertNotNull("Account is NOT deleted", dto);
o }
 }
03/17/16 www.SunilOS.com 14
Assert Methods
assertEquals()
assertTrue()
assertFalse()
assertNotNull()
assertNull()
assertSame()
assertNotSame()
assertArrayEquals()
03/17/16 www.SunilOS.com 15
Annotations
 @Test: public void method, annotated by this
annotation is run as test case.
 @Ignore: It is used to temporary disable a test or group of
tests to be executed. If a class is annotated by @Ignore
then all test methods of this class will be ignored.
03/17/16 www.SunilOS.com 16
Lifecycle Methods
A JUnit class may contain life-cycle
methods.
These methods are defined by following
annotations.
o @BeforeClass
o @AfterClass
o @Before
o @After
03/17/16 www.SunilOS.com 17
JUnit LifeCycle
03/17/16 www.SunilOS.com 18
Life Cycle Annotation
 @BeforeClass: An annotated public static void no-
argument method will be executed before execution of any
test method in the class.
 @AfterClass: An annotated public static void no-
argument method will be executed after all test methods of
this class are executed.
 @Before: this method will be called before each test
method in the Class.
 @After: this method will be called after each test method
in the Class.
03/17/16 www.SunilOS.com 19
Test Suite
A test suite is a collection of test cases.
A test runner is software that runs tests and
reports results.
03/17/16 www.SunilOS.com 20
Test Suite
 public class AllTests {
 public static TestSuite getSuite() {
o TestSuite suite = new TestSuite(“Test All ");
o suite.addTestSuite(AccountServiceTestcase.class);
o suite.addTestSuite(UserServiceTestcase.class);
o return suite;
 }
03/17/16 www.SunilOS.com 21
Test Runner
public static void main(String args[]){
junit.textui.TestRunner.run(getSuite());
}
03/17/16 www.SunilOS.com 22
JUnit Dependency
Jar
o junit-4.12.jar
Maven Dependency
o <dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>4.12</version>
o </dependency>
03/17/16 www.SunilOS.com 23
Disclaimer
This is an educational presentation to enhance the
skill of computer science students.
This presentation is available for free to computer
science students.
Some internet images from different URLs are
used in this presentation to simplify technical
examples and correlate examples with the real
world.
We are grateful to owners of these URLs and
pictures.
www.SunilOS.com 2403/17/16
Thank You!
www.SunilOS.com 25
www.SunilOS.com
03/17/16
1 of 25

Recommended

Log4 J by
Log4 JLog4 J
Log4 JSunil OS
441.2K views30 slides
Java 8 - CJ by
Java 8 - CJJava 8 - CJ
Java 8 - CJSunil OS
954.1K views17 slides
Hibernate by
Hibernate Hibernate
Hibernate Sunil OS
511K views102 slides
Java Basics V3 by
Java Basics V3Java Basics V3
Java Basics V3Sunil OS
713 views67 slides
Jsp/Servlet by
Jsp/ServletJsp/Servlet
Jsp/ServletSunil OS
528K views93 slides
Exception Handling by
Exception HandlingException Handling
Exception HandlingSunil OS
1.5M views28 slides

More Related Content

What's hot

Collections Framework by
Collections FrameworkCollections Framework
Collections FrameworkSunil OS
1.3M views49 slides
JAVA Variables and Operators by
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and OperatorsSunil OS
1.5M views50 slides
Java IO Streams V4 by
Java IO Streams V4Java IO Streams V4
Java IO Streams V4Sunil OS
294 views42 slides
JavaScript by
JavaScriptJavaScript
JavaScriptSunil OS
519K views27 slides
Java Basics by
Java BasicsJava Basics
Java BasicsSunil OS
1.5M views67 slides
Collection v3 by
Collection v3Collection v3
Collection v3Sunil OS
105.5K views63 slides

What's hot(20)

Collections Framework by Sunil OS
Collections FrameworkCollections Framework
Collections Framework
Sunil OS1.3M views
JAVA Variables and Operators by Sunil OS
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and Operators
Sunil OS1.5M views
Java IO Streams V4 by Sunil OS
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
Sunil OS294 views
JavaScript by Sunil OS
JavaScriptJavaScript
JavaScript
Sunil OS519K views
Java Basics by Sunil OS
Java BasicsJava Basics
Java Basics
Sunil OS1.5M views
Collection v3 by Sunil OS
Collection v3Collection v3
Collection v3
Sunil OS105.5K views
Java Input Output and File Handling by Sunil OS
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Sunil OS1.1M views
OOP V3.1 by Sunil OS
OOP V3.1OOP V3.1
OOP V3.1
Sunil OS486 views
Resource Bundle by Sunil OS
Resource BundleResource Bundle
Resource Bundle
Sunil OS506.8K views
Java Threads and Concurrency by Sunil OS
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
Sunil OS1.1M views
Mocking in Java with Mockito by Richard Paul
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with Mockito
Richard Paul14.3K views
Threads V4 by Sunil OS
Threads  V4Threads  V4
Threads V4
Sunil OS319 views
Java 8 Lambda Built-in Functional Interfaces by Ganesh Samarthyam
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
Ganesh Samarthyam3.2K views
Easy data-with-spring-data-jpa by Staples
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpa
Staples3.5K views
Python Part 1 by Sunil OS
Python Part 1Python Part 1
Python Part 1
Sunil OS606.3K views

Similar to JUnit 4

J unit presentation by
J unit presentationJ unit presentation
J unit presentationPriya Sharma
1.5K views26 slides
JUnit Presentation by
JUnit PresentationJUnit Presentation
JUnit Presentationpriya_trivedi
17.7K views26 slides
Unit testing with JUnit by
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnitPokpitch Patcharadamrongkul
1.2K views53 slides
8-testing.pptx by
8-testing.pptx8-testing.pptx
8-testing.pptxssuserd0fdaa
1 view64 slides
J Unit by
J UnitJ Unit
J Unitguest333f37c3
673 views38 slides
SE2018_Lec 20_ Test-Driven Development (TDD) by
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)Amr E. Mohamed
490 views34 slides

Similar to JUnit 4(20)

J unit presentation by Priya Sharma
J unit presentationJ unit presentation
J unit presentation
Priya Sharma1.5K views
JUnit Presentation by priya_trivedi
JUnit PresentationJUnit Presentation
JUnit Presentation
priya_trivedi17.7K views
SE2018_Lec 20_ Test-Driven Development (TDD) by Amr E. Mohamed
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
Amr E. Mohamed490 views
05 junit by mha4
05 junit05 junit
05 junit
mha4671 views
JUnit- A Unit Testing Framework by Onkar Deshpande
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
Onkar Deshpande7.6K views
TestNG Session presented in PB by Abhishek Yadav
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PB
Abhishek Yadav480 views
Junit4&testng presentation by Sanjib Dhar
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentation
Sanjib Dhar1.8K views
Mutation Testing: Start Hunting The Bugs by Ari Waller
Mutation Testing: Start Hunting The BugsMutation Testing: Start Hunting The Bugs
Mutation Testing: Start Hunting The Bugs
Ari Waller107 views

More from Sunil OS

DJango by
DJangoDJango
DJangoSunil OS
124.5K views63 slides
PDBC by
PDBCPDBC
PDBCSunil OS
277.4K views32 slides
OOP v3 by
OOP v3OOP v3
OOP v3Sunil OS
107.9K views56 slides
Threads v3 by
Threads v3Threads v3
Threads v3Sunil OS
104.8K views41 slides
Exception Handling v3 by
Exception Handling v3Exception Handling v3
Exception Handling v3Sunil OS
75K views29 slides
Machine learning ( Part 3 ) by
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )Sunil OS
529.2K views51 slides

More from Sunil OS(18)

DJango by Sunil OS
DJangoDJango
DJango
Sunil OS124.5K views
PDBC by Sunil OS
PDBCPDBC
PDBC
Sunil OS277.4K views
OOP v3 by Sunil OS
OOP v3OOP v3
OOP v3
Sunil OS107.9K views
Threads v3 by Sunil OS
Threads v3Threads v3
Threads v3
Sunil OS104.8K views
Exception Handling v3 by Sunil OS
Exception Handling v3Exception Handling v3
Exception Handling v3
Sunil OS75K views
Machine learning ( Part 3 ) by Sunil OS
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )
Sunil OS529.2K views
Machine learning ( Part 2 ) by Sunil OS
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )
Sunil OS571.7K views
Machine learning ( Part 1 ) by Sunil OS
Machine learning ( Part 1 )Machine learning ( Part 1 )
Machine learning ( Part 1 )
Sunil OS616.1K views
Python Pandas by Sunil OS
Python PandasPython Pandas
Python Pandas
Sunil OS613.6K views
Python part2 v1 by Sunil OS
Python part2 v1Python part2 v1
Python part2 v1
Sunil OS607.9K views
Angular 8 by Sunil OS
Angular 8 Angular 8
Angular 8
Sunil OS531K views
C# Variables and Operators by Sunil OS
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
Sunil OS494.1K views
C# Basics by Sunil OS
C# BasicsC# Basics
C# Basics
Sunil OS481.5K views
Rays Technologies by Sunil OS
Rays TechnologiesRays Technologies
Rays Technologies
Sunil OS915 views
C++ oop by Sunil OS
C++ oopC++ oop
C++ oop
Sunil OS598.3K views
C++ by Sunil OS
C++C++
C++
Sunil OS590.8K views
C Basics by Sunil OS
C BasicsC Basics
C Basics
Sunil OS596.4K views
Java Swing JFC by Sunil OS
Java Swing JFCJava Swing JFC
Java Swing JFC
Sunil OS1M views

Recently uploaded

EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx by
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptxEIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptxISSIP
359 views50 slides
Dance KS5 Breakdown by
Dance KS5 BreakdownDance KS5 Breakdown
Dance KS5 BreakdownWestHatch
69 views2 slides
Psychology KS4 by
Psychology KS4Psychology KS4
Psychology KS4WestHatch
76 views4 slides
11.28.23 Social Capital and Social Exclusion.pptx by
11.28.23 Social Capital and Social Exclusion.pptx11.28.23 Social Capital and Social Exclusion.pptx
11.28.23 Social Capital and Social Exclusion.pptxmary850239
291 views25 slides
Lecture: Open Innovation by
Lecture: Open InnovationLecture: Open Innovation
Lecture: Open InnovationMichal Hron
99 views56 slides
11.30.23 Poverty and Inequality in America.pptx by
11.30.23 Poverty and Inequality in America.pptx11.30.23 Poverty and Inequality in America.pptx
11.30.23 Poverty and Inequality in America.pptxmary850239
149 views33 slides

Recently uploaded(20)

EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx by ISSIP
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptxEIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
ISSIP359 views
Dance KS5 Breakdown by WestHatch
Dance KS5 BreakdownDance KS5 Breakdown
Dance KS5 Breakdown
WestHatch69 views
Psychology KS4 by WestHatch
Psychology KS4Psychology KS4
Psychology KS4
WestHatch76 views
11.28.23 Social Capital and Social Exclusion.pptx by mary850239
11.28.23 Social Capital and Social Exclusion.pptx11.28.23 Social Capital and Social Exclusion.pptx
11.28.23 Social Capital and Social Exclusion.pptx
mary850239291 views
Lecture: Open Innovation by Michal Hron
Lecture: Open InnovationLecture: Open Innovation
Lecture: Open Innovation
Michal Hron99 views
11.30.23 Poverty and Inequality in America.pptx by mary850239
11.30.23 Poverty and Inequality in America.pptx11.30.23 Poverty and Inequality in America.pptx
11.30.23 Poverty and Inequality in America.pptx
mary850239149 views
OEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptx by Inge de Waard
OEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptxOEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptx
OEB 2023 Co-learning To Speed Up AI Implementation in Courses.pptx
Inge de Waard169 views
The Accursed House by Émile Gaboriau by DivyaSheta
The Accursed House  by Émile GaboriauThe Accursed House  by Émile Gaboriau
The Accursed House by Émile Gaboriau
DivyaSheta187 views
JiscOAWeek_LAIR_slides_October2023.pptx by Jisc
JiscOAWeek_LAIR_slides_October2023.pptxJiscOAWeek_LAIR_slides_October2023.pptx
JiscOAWeek_LAIR_slides_October2023.pptx
Jisc93 views
REPRESENTATION - GAUNTLET.pptx by iammrhaywood
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptx
iammrhaywood91 views
Solar System and Galaxies.pptx by DrHafizKosar
Solar System and Galaxies.pptxSolar System and Galaxies.pptx
Solar System and Galaxies.pptx
DrHafizKosar89 views
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively by PECB
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
PECB 574 views
American Psychological Association 7th Edition.pptx by SamiullahAfridi4
American Psychological Association  7th Edition.pptxAmerican Psychological Association  7th Edition.pptx
American Psychological Association 7th Edition.pptx
SamiullahAfridi482 views

JUnit 4

  • 2. 03/17/16 www.SunilOS.com 2 Introduction JUnit is an open source Java testing framework It is used to write and run repeatable tests by Developers. Testing done by JUnit is called Unit Testing. JUnit was originally written by Erich Gamma and Kent Beck.
  • 3. Test A Class – AccountService  Lets have a Class that provides Account Services  Here are methods to perform account services. o add o delete o update o get o list o getBalance 03/17/16 www.SunilOS.com 3 AccountService +add(dto) +update(dto) +delete(dto) +get(id) +list() : List +getBalance() : double AccountDTO +accssor +id +number +name +type +balance
  • 4. Conventional Testing Approach  Write test in the main method  public class TestAccount { o public static void main(String[] args) {  AccountDTO dto = new AccountDTO();  dto.setId(1);  dto.setNumber("SB123456");  dto.setName("sunRays Technologies");  dto.setBalance(10000);  AccountService.add(dto); //Test#1  AccountService.update(dto); //Test#2  AccountService.delete(dto); //Test#3  dto = AccountService.get(1); //Test#4 o }  } 03/17/16 www.SunilOS.com 4
  • 5. Problem ?  AccountService.add(dto); //Test#1  AccountService.update(dto); //Test#2  AccountService.delete(dto); //Test#3  dto = AccountService.get(1); //Test#4  Any exception on any Test will terminate subsequent tests from the execution.  Say if Test#2 has exception then Test#3 and Test#4 will not be executed. If Test#1 has exception then Test#2,#3, and #4 will not be executed. 03/17/16 www.SunilOS.com 5
  • 6. Solution JUnit Framework. Prepare Test Programs. Test program is called Testcase. One Model/Service class will have one JUnit Testcase. Testing is called Unit Testing. 03/17/16 www.SunilOS.com 6
  • 7. What is Unit Testcase A Unit Testcase is a test program to test a Usecase functionality. A Testcase tests the response of a single method to a particular set of input. Unit Testcases are written and run by Developers. 03/17/16 www.SunilOS.com 7
  • 8. What is JUnit JUnit is an open source Java testing framework It is used to write and run repeatable tests by Developers. Testing done by JUnit is called Unit Testing. JUnit was originally written by Erich Gamma and Kent Beck. 03/17/16 www.SunilOS.com 8
  • 9. Features of JUnit Fail and Assertion methods to test expected results. Test suites to execute multiple test cases together. Graphical and textual test runners. 03/17/16 www.SunilOS.com 9
  • 10. Version 4.0 Current version is 4.x. Supports Annotations. 03/17/16 www.SunilOS.com 10
  • 11. What is regression testing When you test new functionality along with old functionality, is called regression testing. Suppose you recently have developed fundTransfer() method, when you test openAccount(), deposit() and withdraw() methods along with newly created fundTransfer() method then it is called regression testing. 03/17/16 www.SunilOS.com 11
  • 12. Add testcase  public class AccountServiceTestcase { o @Test o public void testAdd() {  AccountDTO dto = new AccountDTO();  dto.setId(1);  dto.setNumber("SB123456");  AccountService.add(dto);  dto = AccountService.get(1);  // If DTO is null then record is not added and testcase is fail  if(dto == null){  fail("Account is NOT added");  } o }  } 03/17/16 www.SunilOS.com 12
  • 13. Add testcase assert  public class AccountServiceTestcase { o @Test o public void testAdd() {  AccountDTO dto = new AccountDTO();  dto.setId(1);  dto.setNumber("SB123456");  AccountService.add(dto);  dto = AccountService.get(1);  // If DTO is null then record is not added and testcase is fail  assertNull("Account is NOT deleted", dto); o }  } 03/17/16 www.SunilOS.com 13
  • 14. Delete testcase assert  public class AccountServiceTestcase { o @Test o public void testDelete() {  AccountDTO dto = new AccountDTO();  dto.setId(1);  AccountService.delete(dto);  dto = AccountService.get(1);  // If DTO is NOT null then record is not deleted and testcase is fail  assertNotNull("Account is NOT deleted", dto); o }  } 03/17/16 www.SunilOS.com 14
  • 16. Annotations  @Test: public void method, annotated by this annotation is run as test case.  @Ignore: It is used to temporary disable a test or group of tests to be executed. If a class is annotated by @Ignore then all test methods of this class will be ignored. 03/17/16 www.SunilOS.com 16
  • 17. Lifecycle Methods A JUnit class may contain life-cycle methods. These methods are defined by following annotations. o @BeforeClass o @AfterClass o @Before o @After 03/17/16 www.SunilOS.com 17
  • 19. Life Cycle Annotation  @BeforeClass: An annotated public static void no- argument method will be executed before execution of any test method in the class.  @AfterClass: An annotated public static void no- argument method will be executed after all test methods of this class are executed.  @Before: this method will be called before each test method in the Class.  @After: this method will be called after each test method in the Class. 03/17/16 www.SunilOS.com 19
  • 20. Test Suite A test suite is a collection of test cases. A test runner is software that runs tests and reports results. 03/17/16 www.SunilOS.com 20
  • 21. Test Suite  public class AllTests {  public static TestSuite getSuite() { o TestSuite suite = new TestSuite(“Test All "); o suite.addTestSuite(AccountServiceTestcase.class); o suite.addTestSuite(UserServiceTestcase.class); o return suite;  } 03/17/16 www.SunilOS.com 21
  • 22. Test Runner public static void main(String args[]){ junit.textui.TestRunner.run(getSuite()); } 03/17/16 www.SunilOS.com 22
  • 23. JUnit Dependency Jar o junit-4.12.jar Maven Dependency o <dependency>  <groupId>junit</groupId>  <artifactId>junit</artifactId>  <version>4.12</version> o </dependency> 03/17/16 www.SunilOS.com 23
  • 24. Disclaimer This is an educational presentation to enhance the skill of computer science students. This presentation is available for free to computer science students. Some internet images from different URLs are used in this presentation to simplify technical examples and correlate examples with the real world. We are grateful to owners of these URLs and pictures. www.SunilOS.com 2403/17/16