SlideShare a Scribd company logo
Write an example of a unit test for a Class methods using JUnitframework
Write an example of a unit test for a Class methods using JUnitframework
Solution
Example of test case java using JUnitframework:
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestJunit {
String message = "Hello World";
MessageUtil messageUtil = new MessageUtil(message);
@Test
public void testPrintMessage() {
assertEquals(message,messageUtil.printMessage());
}
}
Test suit Examples:
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
//JUnit Suite Test
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestJunit1.class ,TestJunit2.class
})
public class JunitTestSuite {
}
import org.junit.Test;
import org.junit.Ignore;
import static org.junit.Assert.assertEquals;
public class TestJunit1 {
String message = "Robert";
MessageUtil messageUtil = new MessageUtil(message);
@Test
public void testPrintMessage() {
System.out.println("Inside testPrintMessage()");
assertEquals(message, messageUtil.printMessage());
}
}
import org.junit.Test;
import org.junit.Ignore;
import static org.junit.Assert.assertEquals;
public class TestJunit2 {
String message = "Robert";
MessageUtil messageUtil = new MessageUtil(message);
@Test
public void testSalutationMessage() {
System.out.println("Inside testSalutationMessage()");
message = "Hi!" + "Robert";
assertEquals(message,messageUtil.salutationMessage());
}
}

More Related Content

Similar to Write an example of a unit test for a Class methods using JUnitfr.pdf

TestNG vs Junit
TestNG vs JunitTestNG vs Junit
TestNG vs Junit
Büşra İçöz
 
J unit presentation
J unit presentationJ unit presentation
J unit presentationPriya Sharma
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
priya_trivedi
 
Junit
JunitJunit
05 junit
05 junit05 junit
05 junit
mha4
 
Test ng tutorial
Test ng tutorialTest ng tutorial
Test ng tutorial
Srikrishna k
 
Junit 4.0
Junit 4.0Junit 4.0
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
OpenDaylight
 
Introduction to Testing Frameworks
Introduction to Testing Frameworks Introduction to Testing Frameworks
Introduction to Testing Frameworks
Hemant Shori
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good Tests
Tomek Kaczanowski
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
Pokpitch Patcharadamrongkul
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
Tomek Kaczanowski
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
Марія Русин
 
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeJUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
Ted Vinke
 
An Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAn Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDD
Ahmed Ehab AbdulAziz
 
L08 Unit Testing
L08 Unit TestingL08 Unit Testing
L08 Unit Testing
Ólafur Andri Ragnarsson
 
Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
Amila Paranawithana
 
Power mock
Power mockPower mock
Power mock
Piyush Mittal
 

Similar to Write an example of a unit test for a Class methods using JUnitfr.pdf (20)

TestNG vs Junit
TestNG vs JunitTestNG vs Junit
TestNG vs Junit
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Unit test
Unit testUnit test
Unit test
 
Junit
JunitJunit
Junit
 
05 junit
05 junit05 junit
05 junit
 
Test ng tutorial
Test ng tutorialTest ng tutorial
Test ng tutorial
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
 
Introduction to Testing Frameworks
Introduction to Testing Frameworks Introduction to Testing Frameworks
Introduction to Testing Frameworks
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good Tests
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
 
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeJUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
 
An Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAn Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDD
 
L08 Unit Testing
L08 Unit TestingL08 Unit Testing
L08 Unit Testing
 
Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
 
Junit
JunitJunit
Junit
 
Power mock
Power mockPower mock
Power mock
 

More from arbaazrabs

Find the indicial roots then solve the following ODE using series. Yo.pdf
Find the indicial roots then solve the following ODE using series. Yo.pdfFind the indicial roots then solve the following ODE using series. Yo.pdf
Find the indicial roots then solve the following ODE using series. Yo.pdf
arbaazrabs
 
Design verilog code [in ISE Project Navigator Verilog Module, Veril.pdf
Design verilog code [in ISE Project Navigator Verilog Module, Veril.pdfDesign verilog code [in ISE Project Navigator Verilog Module, Veril.pdf
Design verilog code [in ISE Project Navigator Verilog Module, Veril.pdf
arbaazrabs
 
DNA and RNA are both stands of nucleotides but RNA can carry out for .pdf
DNA and RNA are both stands of nucleotides but RNA can carry out for .pdfDNA and RNA are both stands of nucleotides but RNA can carry out for .pdf
DNA and RNA are both stands of nucleotides but RNA can carry out for .pdf
arbaazrabs
 
Distinguish between the concepts of stereotyping, prejudice, and dis.pdf
Distinguish between the concepts of stereotyping, prejudice, and dis.pdfDistinguish between the concepts of stereotyping, prejudice, and dis.pdf
Distinguish between the concepts of stereotyping, prejudice, and dis.pdf
arbaazrabs
 
38 Cats eat only animals. Something fuzzy exists. Everything thats .pdf
38 Cats eat only animals. Something fuzzy exists. Everything thats .pdf38 Cats eat only animals. Something fuzzy exists. Everything thats .pdf
38 Cats eat only animals. Something fuzzy exists. Everything thats .pdf
arbaazrabs
 
An octapeptide was hydrolyzed and the amino acids separated. It was .pdf
An octapeptide was hydrolyzed and the amino acids separated. It was .pdfAn octapeptide was hydrolyzed and the amino acids separated. It was .pdf
An octapeptide was hydrolyzed and the amino acids separated. It was .pdf
arbaazrabs
 
c. hydrophillic heads; sticking out toward the interior and exterior.pdf
c. hydrophillic heads; sticking out toward the interior and exterior.pdfc. hydrophillic heads; sticking out toward the interior and exterior.pdf
c. hydrophillic heads; sticking out toward the interior and exterior.pdf
arbaazrabs
 
Biology Lab questions1. Units of amino acid are carried to the ri.pdf
Biology Lab questions1. Units of amino acid are carried to the ri.pdfBiology Lab questions1. Units of amino acid are carried to the ri.pdf
Biology Lab questions1. Units of amino acid are carried to the ri.pdf
arbaazrabs
 
Why is it important to use several sources of power and influence, r.pdf
Why is it important to use several sources of power and influence, r.pdfWhy is it important to use several sources of power and influence, r.pdf
Why is it important to use several sources of power and influence, r.pdf
arbaazrabs
 
What is special about the colugos teethLower incisors are comb-li.pdf
What is special about the colugos teethLower incisors are comb-li.pdfWhat is special about the colugos teethLower incisors are comb-li.pdf
What is special about the colugos teethLower incisors are comb-li.pdf
arbaazrabs
 
write simple program in c++ in which source reads a file of integers.pdf
write simple program in c++ in which source reads a file of integers.pdfwrite simple program in c++ in which source reads a file of integers.pdf
write simple program in c++ in which source reads a file of integers.pdf
arbaazrabs
 
whats in plasmaSolutionAnswerBlood is the fluid connecti.pdf
whats in plasmaSolutionAnswerBlood is the fluid connecti.pdfwhats in plasmaSolutionAnswerBlood is the fluid connecti.pdf
whats in plasmaSolutionAnswerBlood is the fluid connecti.pdf
arbaazrabs
 
What is a reason we want to write in a concise manner 1. To elimina.pdf
What is a reason we want to write in a concise manner 1. To elimina.pdfWhat is a reason we want to write in a concise manner 1. To elimina.pdf
What is a reason we want to write in a concise manner 1. To elimina.pdf
arbaazrabs
 
What are the advantages of Credit Suisse’s new supplier managemente.pdf
What are the advantages of Credit Suisse’s new supplier managemente.pdfWhat are the advantages of Credit Suisse’s new supplier managemente.pdf
What are the advantages of Credit Suisse’s new supplier managemente.pdf
arbaazrabs
 
The PRIMARY structure of a protein isformed by alpha helices and .pdf
The PRIMARY structure of a protein isformed by alpha helices and .pdfThe PRIMARY structure of a protein isformed by alpha helices and .pdf
The PRIMARY structure of a protein isformed by alpha helices and .pdf
arbaazrabs
 
The figure below shows the chromosomes in a cell for some species (.pdf
The figure below shows the chromosomes in a cell for some species (.pdfThe figure below shows the chromosomes in a cell for some species (.pdf
The figure below shows the chromosomes in a cell for some species (.pdf
arbaazrabs
 
The addButton_Click procedure should perform the following three tas.pdf
The addButton_Click procedure should perform the following three tas.pdfThe addButton_Click procedure should perform the following three tas.pdf
The addButton_Click procedure should perform the following three tas.pdf
arbaazrabs
 
A mistake occurs during lambda phage excision from the E. coli genom.pdf
A mistake occurs during lambda phage excision from the E. coli genom.pdfA mistake occurs during lambda phage excision from the E. coli genom.pdf
A mistake occurs during lambda phage excision from the E. coli genom.pdf
arbaazrabs
 
Assume a System Engineering class has 27 students, of which one thir.pdf
Assume a System Engineering class has 27 students, of which one thir.pdfAssume a System Engineering class has 27 students, of which one thir.pdf
Assume a System Engineering class has 27 students, of which one thir.pdf
arbaazrabs
 
1.) Explain what type of mechanism and application use a  marine ste.pdf
1.) Explain what type of mechanism and application use a  marine ste.pdf1.) Explain what type of mechanism and application use a  marine ste.pdf
1.) Explain what type of mechanism and application use a  marine ste.pdf
arbaazrabs
 

More from arbaazrabs (20)

Find the indicial roots then solve the following ODE using series. Yo.pdf
Find the indicial roots then solve the following ODE using series. Yo.pdfFind the indicial roots then solve the following ODE using series. Yo.pdf
Find the indicial roots then solve the following ODE using series. Yo.pdf
 
Design verilog code [in ISE Project Navigator Verilog Module, Veril.pdf
Design verilog code [in ISE Project Navigator Verilog Module, Veril.pdfDesign verilog code [in ISE Project Navigator Verilog Module, Veril.pdf
Design verilog code [in ISE Project Navigator Verilog Module, Veril.pdf
 
DNA and RNA are both stands of nucleotides but RNA can carry out for .pdf
DNA and RNA are both stands of nucleotides but RNA can carry out for .pdfDNA and RNA are both stands of nucleotides but RNA can carry out for .pdf
DNA and RNA are both stands of nucleotides but RNA can carry out for .pdf
 
Distinguish between the concepts of stereotyping, prejudice, and dis.pdf
Distinguish between the concepts of stereotyping, prejudice, and dis.pdfDistinguish between the concepts of stereotyping, prejudice, and dis.pdf
Distinguish between the concepts of stereotyping, prejudice, and dis.pdf
 
38 Cats eat only animals. Something fuzzy exists. Everything thats .pdf
38 Cats eat only animals. Something fuzzy exists. Everything thats .pdf38 Cats eat only animals. Something fuzzy exists. Everything thats .pdf
38 Cats eat only animals. Something fuzzy exists. Everything thats .pdf
 
An octapeptide was hydrolyzed and the amino acids separated. It was .pdf
An octapeptide was hydrolyzed and the amino acids separated. It was .pdfAn octapeptide was hydrolyzed and the amino acids separated. It was .pdf
An octapeptide was hydrolyzed and the amino acids separated. It was .pdf
 
c. hydrophillic heads; sticking out toward the interior and exterior.pdf
c. hydrophillic heads; sticking out toward the interior and exterior.pdfc. hydrophillic heads; sticking out toward the interior and exterior.pdf
c. hydrophillic heads; sticking out toward the interior and exterior.pdf
 
Biology Lab questions1. Units of amino acid are carried to the ri.pdf
Biology Lab questions1. Units of amino acid are carried to the ri.pdfBiology Lab questions1. Units of amino acid are carried to the ri.pdf
Biology Lab questions1. Units of amino acid are carried to the ri.pdf
 
Why is it important to use several sources of power and influence, r.pdf
Why is it important to use several sources of power and influence, r.pdfWhy is it important to use several sources of power and influence, r.pdf
Why is it important to use several sources of power and influence, r.pdf
 
What is special about the colugos teethLower incisors are comb-li.pdf
What is special about the colugos teethLower incisors are comb-li.pdfWhat is special about the colugos teethLower incisors are comb-li.pdf
What is special about the colugos teethLower incisors are comb-li.pdf
 
write simple program in c++ in which source reads a file of integers.pdf
write simple program in c++ in which source reads a file of integers.pdfwrite simple program in c++ in which source reads a file of integers.pdf
write simple program in c++ in which source reads a file of integers.pdf
 
whats in plasmaSolutionAnswerBlood is the fluid connecti.pdf
whats in plasmaSolutionAnswerBlood is the fluid connecti.pdfwhats in plasmaSolutionAnswerBlood is the fluid connecti.pdf
whats in plasmaSolutionAnswerBlood is the fluid connecti.pdf
 
What is a reason we want to write in a concise manner 1. To elimina.pdf
What is a reason we want to write in a concise manner 1. To elimina.pdfWhat is a reason we want to write in a concise manner 1. To elimina.pdf
What is a reason we want to write in a concise manner 1. To elimina.pdf
 
What are the advantages of Credit Suisse’s new supplier managemente.pdf
What are the advantages of Credit Suisse’s new supplier managemente.pdfWhat are the advantages of Credit Suisse’s new supplier managemente.pdf
What are the advantages of Credit Suisse’s new supplier managemente.pdf
 
The PRIMARY structure of a protein isformed by alpha helices and .pdf
The PRIMARY structure of a protein isformed by alpha helices and .pdfThe PRIMARY structure of a protein isformed by alpha helices and .pdf
The PRIMARY structure of a protein isformed by alpha helices and .pdf
 
The figure below shows the chromosomes in a cell for some species (.pdf
The figure below shows the chromosomes in a cell for some species (.pdfThe figure below shows the chromosomes in a cell for some species (.pdf
The figure below shows the chromosomes in a cell for some species (.pdf
 
The addButton_Click procedure should perform the following three tas.pdf
The addButton_Click procedure should perform the following three tas.pdfThe addButton_Click procedure should perform the following three tas.pdf
The addButton_Click procedure should perform the following three tas.pdf
 
A mistake occurs during lambda phage excision from the E. coli genom.pdf
A mistake occurs during lambda phage excision from the E. coli genom.pdfA mistake occurs during lambda phage excision from the E. coli genom.pdf
A mistake occurs during lambda phage excision from the E. coli genom.pdf
 
Assume a System Engineering class has 27 students, of which one thir.pdf
Assume a System Engineering class has 27 students, of which one thir.pdfAssume a System Engineering class has 27 students, of which one thir.pdf
Assume a System Engineering class has 27 students, of which one thir.pdf
 
1.) Explain what type of mechanism and application use a  marine ste.pdf
1.) Explain what type of mechanism and application use a  marine ste.pdf1.) Explain what type of mechanism and application use a  marine ste.pdf
1.) Explain what type of mechanism and application use a  marine ste.pdf
 

Recently uploaded

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 

Write an example of a unit test for a Class methods using JUnitfr.pdf

  • 1. Write an example of a unit test for a Class methods using JUnitframework Write an example of a unit test for a Class methods using JUnitframework Solution Example of test case java using JUnitframework: import org.junit.Test; import static org.junit.Assert.assertEquals; public class TestJunit { String message = "Hello World"; MessageUtil messageUtil = new MessageUtil(message); @Test public void testPrintMessage() { assertEquals(message,messageUtil.printMessage()); } } Test suit Examples: import org.junit.runner.RunWith; import org.junit.runners.Suite; //JUnit Suite Test @RunWith(Suite.class) @Suite.SuiteClasses({ TestJunit1.class ,TestJunit2.class }) public class JunitTestSuite { } import org.junit.Test; import org.junit.Ignore; import static org.junit.Assert.assertEquals; public class TestJunit1 { String message = "Robert"; MessageUtil messageUtil = new MessageUtil(message); @Test public void testPrintMessage() {
  • 2. System.out.println("Inside testPrintMessage()"); assertEquals(message, messageUtil.printMessage()); } } import org.junit.Test; import org.junit.Ignore; import static org.junit.Assert.assertEquals; public class TestJunit2 { String message = "Robert"; MessageUtil messageUtil = new MessageUtil(message); @Test public void testSalutationMessage() { System.out.println("Inside testSalutationMessage()"); message = "Hi!" + "Robert"; assertEquals(message,messageUtil.salutationMessage()); } }