JUNIT—Java Unit Testing.
JUNIT is a one kind of framework.
Easy to set the verification point
Easy to verify the business Logic
User Friendly
Easy to identify positive, negative, failed and skipped test cases.
Here there is no main method we are using some annotations.
Download the junit jar
“Junit 4.12.jar”
If we were facing any error in junit while run the test case then need to
download one more jar file.
“Hamcrest-core-1.3.jar”
Add the junit jar in the eclipse build path
@BeforeClass
@Before
@Test
@After
@AfterClass
@Ignore
@Runwith
@Suite
The annotated method will be run before the first test method in the class is
invoked.
Before Class method should be static.
The annotated method will be run after all the test method will be executed.
After Class method should be static.
The annotated method will be run before invoke the each and every test method.
The annotated method will be run after each and every test method will be
executed.
The annotated method is a part of test case.
“@Test is considered as the main method.”
Without @Test we can’t run the program but without remaining annotation we
can run the program.
“If we are having multiple @Test, the methods will be executed based upon the
ascending order of the method name.”
All method should be public
@BeforeClass and @AfterClass method should be public static
@BeforeClass
@Before
@Test (aTest) (Based on ascending order)
@After
@Before
@Test (bTest) (Based on ascending order)
@After
@AfterClass
"Assert" mean validation fails the execution of that particular test method
is stopped and the test method is marked as failed and it will go to next
test.
"Verify", mean the test method continues execution even after the failure
of an assertion statement. Although the test method will still be marked as
failed but the remaining statements of the test method will be executed
normally.
Class Name: Assert
Method Name: assertTrue (Boolean condition)
assertEquals (Expected, Actual)
If we are facing any assertion error, the program is not terminated. The
particular test only stopped but it will go to next test and the test will be
marked as failed.
The annotated method will be used to ignore the particular test from multiple
tests.
If we want to run multiple test class mean we are using suite class.
Suite: Collection of test cases.
Test case: Collection of tests.