Unit Integration Regression Tesing Manual
Unit Integration Regression Tesing Manual
Unit Integration Regression Tesing Manual
Aim:
To develop JUnit test cases for a given Java Class and generate unit test report.
Steps Involved:
Steps in creating a JUnit Test case and Executing it in NetBeans and Eclipse Enviornment
A unit test is to test a smaller unit of code, e.g. methods. Writing a unit test to test the individual
unit of code is one of the best development practices and helps to find bug earlier in the
development cycle. Though there is another unit testing framework available in Java
e.g. TestNG, JUnit has its own place among Java developers
The main difference between JUnit 4 and JUnit 3 is that, JUnit4 is based on annotation feature of
Java 1.5 and easy to write, while JUnit 3 uses “test” keyword, to identify test methods.
This will run all the JUnit tests declared in this class and will pass if all the tests run successfully
and pass the condition tested by various assert statements and fail if any of the JUnit tests failed.
The eclipse will print stack trace and hyperlink to the failed test and you can go and fix the
problem.
An error is when some other Exception occurs due to programming mistakes, such as
a NullPointerException or an ArrayIndexOutOfBoundsException. Both errors and failures are
not good for your code. A good Junit test case should be able to bring failure and error alike.
You should also ensure that your JUnit test case should pass always and doesn't throw any errors
or failures.
Go to File → New → Other... → Java → JUnit → TestSuite, and click Next>. Select all the
classes, and click Finish. Once created, You can run this test suite the same way you run other
JUnit tests. The result of the JUnit test suite will also show in JUnit console-like the previous
run.
How to write JUnit tests in Netbeans
JUnit support in Netbeans is also great and seamless. Here is the steps to create JUnit test in
Netbeans
3. Now Select a Java Class --> Right click --> Tools --> Create Junit tests
this will create Junit test class for all the methods of selected Java class.
Code
Here is complete code example of, How to write unit test in Java using JUnit framework. In this
example, we have a Java class called Calculator, which has two
methods add() and multiply() and takes variable arguments. In this JUnit tutorial, we will write
JUnit testcases, to test these two methods.
/**
*/
public class Calculator {
public int add(int... number) {
int total = 0;
for (int i : number) {
total += i;
}
return total;
}
public int multiply(int... number) {
int product = 0;
for (int i : number) {
product *= i;
}
return product;
}
import static org.junit.Assert.*;
import org.junit.Test;
/**
*/
public class CalculatorTest {
@Test
public void testAdd() {
Calculator calc = new Calculator();
assertEquals(60, calc.add(10,20,30));
}
@Test
public void testMultiply() {
Calculator calc = new Calculator();
assertEquals(6000, calc.multiply(10,20,30));
}
References:
Read more: https://javarevisited.blogspot.com/2013/03/how-to-write-unit-test-in-java-eclipse-
netbeans-example-run.html#ixzz7J8HDKz9U
Sample:
https://youtu.be/Vnyeq3ZS_1Q
https://youtu.be/prv8-8ae8Hs
Perform Integration Testing using Junit
Aim
Procedure
Step 3: From the created project, right click and New-> Java Class
/**
*/
float billamt=amt-disc;
System.out.println("Bill Amount="+billamt);
return billamt;
}
Step 5: Create Test with a Test Name with Integration Tests Checked
Step 6: Create JUnit test cases for the above two units to perform Integration testing
@Test
System.out.println("discal");
// TODO review the generated test code and remove the default call to fail.
/**
*/
@Test
System.out.println("bill");
float disc1=1000.0F;
float expResult=amt-disc;
// TODO review the generated test code and remove the default call to fail.
Step 7: Right click Test code and Click RunTest, the tests will be executed.
Screenshots
Create Tests
Execute Tests
Positive Result
Negative Result
Result
Procedure
Step 1 – Open Google Chrome -> Search for Chrome Extension for Selenium-Object Finder
https://www.incredibleindia.org
Result:
The automation testing using Selenium Object Finder is done and the processes are analyzed.
Web application testing with Capture and Playback using Selenium IDE
Aim
To perform web application testing with Capture and Playback using Selenium IDE.
Procedure
Step 1: Open Google Chrome, search for Chrome Extention on “Selenium IDE”
Thus the capture and playback of test cases are done for web application testing as a regression test
suite.