You are on page 1of 16

JUNIT

AUTOMATION FRAMEWORK

• A test automation framework is a set of


concepts, and practices that provide support
for automated software testing
• It is a methodology built to successfully carry
out test automation
TYPES OF AUTOMATION FRAMEWORK

• Linear Scripting Framework


• Modular Testing Framework
• Data Driven Testing Framework
• Keyword Driven Testing Framework
• Hybrid Testing Framework
ADVANTAGES OF AUTOMATION
FRAMEWORK
• Reusability of code
• Maximum coverage
• Recovery scenario
• Low-cost maintenance
• Minimal manual intervention
• Easy Reporting
UNDERSTANDING UNIT TESTING
FRAMEWORKS
• A unit test is a piece of code written by a
developer that exercises a very small, specific
area of functionality applied to one of the units
of the code being tested
• Identifies defects early in the development
cycle
• Testing forces the programmers to read and
analyze their code, thus removing defects
through constant code verification.
UNIT TESTING FRAMEWORKS
• Automated tests support maintainability and
extensibility along with efficiency
• A xUnit Testing Framework lets a programmer
associate Classes and Methods to
corresponding Test Classes and Test Methods
• Automation is achieved by automatically
setting up a testing context, calling each test
case, verifying their corresponding expected
result, and reporting the status of all tests
JUNIT TESTING
In Java, the standard unit testing framework is
known as Junit
Test Cases and Test Results are Java objects
CONFIGURING JUNIT IN ECLIPSE
• We need to configure or verify java
development kit (JDK) in our machine
• right click on project and click on property >
Build Path > Configure Build Path and add the
junit-4.10.jar in the libraries using the button
Add External Jar
• Create a test class TestJunit in the project
• run as JUnit to verify the output of the
program and Verify the result
JUNIT ANNOTATIONS
•To execute Selenium WebDriver testing using JUnit
we have to add JUnit annotations in your test
•We are using following most commonly used five
annotations
@Test
@Before
@After
@BeforeClass
@AfterClass
JUNIT ANNOTATIONS
setUp()this method
• Used for initializing input (create an object)
method that initializes common object the
setUp() method before a each test is run.
JUNIT ANNOTATIONS
TearDown() method
• To cleanup those objects
• The JUnit framework automatically invokes
tearDown() method after each test is run.
Test method()
• Junit calls one test method
• It call multiple methods to test
RUNNING TESTS IN JUNIT

• Run As JUnit Test and verify the result


• Go to the JUnit view and expand all the tests
that ran
• Right-click on the desired test method and
click Run
RUNNING TESTS IN JUNIT
JUNIT ASSERTIONS

List of different types of assertion statements


that you can use to test your code
• assertEquals(expected, actual)
• assertEquals(message, expected, actual)
• fail()
• fail(message)
• failNotEquals(message, expected, actual)
JUNIT ASSERTION
Example for Junit Program
public class BookTest2 extends TestCase {

private Collection collection;

protected void setUp() {


collection = new ArrayList();
}

protected void tearDown() {


collection.clear();
}

public void testEmptyCollection(){


assertTrue(collection.isEmpty());
}
}
Thank You!!!

You might also like