Page History
Overview
In this tutorial, we will create an Java Test class with multiple Test Cases, implemented in Java.
Description
The test case validates a Calculator class and exploits some TestNG features such as the ability of validating the same Test against multiple input values, and also the possibility of linking Tests with requirements in Jira using NUnit's Test attributes.
...
Code Block | ||||
---|---|---|---|---|
| ||||
package com.xpand.java; public class Calculator { // Square function public static int Square(int num) { return num*num; } // Add two integers and returns the sum public static int Add(int num1, int num2 ) { return num1 + num2; } // Add two integers and returns the sum public static double Add(double num1, double num2 ) { return num1 + num2; } // Multiply two integers and retuns the result public static int Multiply(int num1, int num2 ) { return num1 * num2; } public static int Divide(int num1, int num2 ) { return num1 / num2; } // Subtracts small number from big number public static int Subtract(int num1, int num2 ) { if ( num1 > num2 ) { return num1 - num2; } return num2 - num1; } } |
Example 1: Using TestNG built-in capabilities
This examples uses the standard built-in TestNG capabilities.
...
It can also be seen that the Test "CanAddNumbers" was automatically linked to the sum requirement (i.e., the user story "CALC-1").
References
...