Home / Interview /Step by step tutori...
Srinivasan G
2024-01-23
0 mins read
Create new Project folder through the following navigation flow:
File->New->Others->Maven project. The user is required to enter the Project folder name in a new window that appears. Below are the screenshots for the same:
Select
Project folder -> src folder -> Right-click on the src folder -> Select New -> Junit Test Case.
Let’s now create a basic JUnit 4 test.
Under the package DLAJUNIT.COM, JUnit test class file has been created and we have included a method test().
This method verifies whether the title variable contains the string that is being passed in the condition.
The comparison of the expected condition is being performed by the specific JUnit method – assertTrue(). This method will check whether the title variable contains some specific word of the
expected condition.
@Test annotation is also being added here that defines the test case in a JUnit class file.
Similar to this, by putting many methods in place and giving each one a @Test annotation, you can have multiple test cases in one class file.
Executing the code snippet below should pass the test because the actual string contains the
expected string value.
1. The Console displays the message as follows:
‘Beforeclass passed’
‘Verify the title name’
‘Afterclass passed’
2. The JUnit result page shows the total number of test cases run, errors, and failures, i.e. Run: 1/1 (indicating 1 testcase out of 1 testcase ran), Errors: 0 (no errors are found in the test case ran), Failures: 0(no test case got failed)
3. The amount of time required to complete the tests' execution.
4. If all test cases pass, a green bar is shown.
5. You can see various icons on the JUnit tab, just above the timestamp: The first icon shows ‘Next Failed Test’, the second icon shows ‘Previous Failed Test’, and the third icon with a blue and red cross filters out only Failed tests. The icon next to this allows you to only view test cases that were skipped during execution.
INQUIRY
By tapping continuing, you agree to our Privacy Policy and Terms & Conditions
SkillAhead Solutions
USA
1603, Capitol Avenue, Suite 413A, 2659, Cheyenne, WY 82001, USA
`Copyright © DevLabs Alliance. All rights Reserved`
|
Refund & Reschedule Policy
Privacy Policy
Terms of Use