Unit Test Programming -
Session 1
Amin Arab
Sharivar 98
Tosan
https://www.linkedin.com/in/amin-arab-a653b13a/
ISTQB
V Model
Test Pyramid
JUnit
• Maven Dependencies
• Basic Annotation of Test
• Assertion
• Property
• List
• Map
• Expected Exceptions Test
• Parameterized Test
• Timeout Test
• Organize Test
• Suite Test
• Category Test
• Ignore a Test
• Order Test
JUnit vs TestNG
Feature JUnit 4 TestNG
test annotation @Test @Test
run before all tests in this suite have run — @BeforeSuite
run after all tests in this suite have run — @AfterSuite
run before the test — @BeforeTest
run after the test — @AfterTest
run before the first test method that belongs to any of these
groups is invoked
— @BeforeGroups
run after the last test method that belongs to any of these groups
is invoked
— @AfterGroups
run before the first test method in the current class is invoked @BeforeClass @BeforeClass
run after all the test methods in the current class have been run @AfterClass @AfterClass
run before each test method @Before @BeforeMethod
run after each test method @After @AfterMethod
ignore test @ignore @Test(enbale=false)
expected exception @Test(expected = ArithmeticException.class) @Test(expectedExceptions = ArithmeticException.class)
timeout @Test(timeout = 1000) @Test(timeout = 1000)
JUnit 5
• Features
• The entire framework was contained in a single jar library
• JUnit 5 allows multiple runners to work simultaneously
• JUnit 5 makes good use of Java 8 features
• Differences
• JUnit Platform – this module scopes all the extension frameworks we might
be interested in test execution, discovery, and reporting
• JUnit Vintage – this module allows backward compatibility with JUnit 4 or
even JUnit 3
Mocking
• Hello mocking , goodbey Weblogic
• RunWith
• InjectMocks
• Mock
• Adding Behavior
• Verifying Behavior
• Expecting Calls
• PowerMock
• Set Private property
References
• https://www.mkyong.com/tutorials/junit-tutorials/
• https://www.baeldung.com/junit-5-migration
Codes
• https://github.com/aminarab/JUnit-training
• https://github.com/aminarab/Mockito-Training

Unit test programming session 1

  • 1.
    Unit Test Programming- Session 1 Amin Arab Sharivar 98 Tosan https://www.linkedin.com/in/amin-arab-a653b13a/
  • 2.
  • 3.
  • 4.
  • 5.
    JUnit • Maven Dependencies •Basic Annotation of Test • Assertion • Property • List • Map • Expected Exceptions Test • Parameterized Test • Timeout Test • Organize Test • Suite Test • Category Test • Ignore a Test • Order Test
  • 6.
    JUnit vs TestNG FeatureJUnit 4 TestNG test annotation @Test @Test run before all tests in this suite have run — @BeforeSuite run after all tests in this suite have run — @AfterSuite run before the test — @BeforeTest run after the test — @AfterTest run before the first test method that belongs to any of these groups is invoked — @BeforeGroups run after the last test method that belongs to any of these groups is invoked — @AfterGroups run before the first test method in the current class is invoked @BeforeClass @BeforeClass run after all the test methods in the current class have been run @AfterClass @AfterClass run before each test method @Before @BeforeMethod run after each test method @After @AfterMethod ignore test @ignore @Test(enbale=false) expected exception @Test(expected = ArithmeticException.class) @Test(expectedExceptions = ArithmeticException.class) timeout @Test(timeout = 1000) @Test(timeout = 1000)
  • 7.
    JUnit 5 • Features •The entire framework was contained in a single jar library • JUnit 5 allows multiple runners to work simultaneously • JUnit 5 makes good use of Java 8 features • Differences • JUnit Platform – this module scopes all the extension frameworks we might be interested in test execution, discovery, and reporting • JUnit Vintage – this module allows backward compatibility with JUnit 4 or even JUnit 3
  • 8.
    Mocking • Hello mocking, goodbey Weblogic • RunWith • InjectMocks • Mock • Adding Behavior • Verifying Behavior • Expecting Calls • PowerMock • Set Private property
  • 9.
  • 10.