Test NG Setup
Test NG Setup
Install Maven 2.2.1 from http://maven.apache.org/download.html or you can get it from shared
Directory
After the above step add following Environment Variable (in my case)
- Variable Name: M2_Home
Variable Value: C:\TestNg\apache-maven-3.2.1\apache-maven-3.2.1
- Variable Name: M2
Variable Value: C:\TestNg\apache-maven-3.2.1\apache-maven-3.2.1\bin
Installation Of Perforce
Step 5: After that Go to installation Directory of perforce in my case “C:\Program Files (x86)\
Perforce” click on P4v.exe
Enter the server name “pun-rnd-scm01.bmc.com:11842”
Enter your Username, Workspace Name and Click on OK.
Step 4: On your system tray right click on code collaborator icon and select open GUI.
Step 5: You will get the Window as below, Click on add.
Running Testcase
Because the TestNG framework is Java, this means that we are using the AR System Java API
to make calls to the AR Server. You can get a copy of the Javadoc’s by looking in the AR
Server's install directory, specifically the arserver\api\lib directory. In that directory there will be
a file named ardocXX.jar where XX is the version number. You can extract that file and open the
index.html file in a web browser. All API calls are made from the ARServerUser class. In the C#
automation framework we use the .NET API and the BMC.ARSystem.Server class to make all
API calls. The ARServerUser class serves the same purpose but you'll notice that the names of
the API calls may not be the same.
Naming Conventions
The following table shows the base package name for each product.
Product Package
API com.bmc.arsys.tests.api
AR Import com.bmc.arsys.tests.arimport
AR Server com.bmc.arsys.tests.server
Email Engine com.bmc.arsys.tests.emailengine
Web Services com.bmc.arsys.tests.webservices
Test class names should also reflect what you are testing. If you are writing server tests for
merge entry then put them in the com.bmc.arsys.tests.server.entries package with a class name
like MergeEntry. The names of the methods should be descriptive as well. The test method's
name should be a short version of the test description. For example, if you're verifying that the
status history field is updated during merge entry, a good function name would be
verifyStatusHistoryUpdated.
Configuration methods
Just like C# and JUnit frameworks, you can perform some setup and teardown work during a
test. There are four types of configuration methods we will use in TestNG, denoted by the
annotation used. Note: You must include the alwaysRun = true on the configuration methods or
else they may not be run because we run with groups from the automation controllers.
@BeforeClass(alwaysRun = true)
public void classSetup()
{
// gets called before any test in this class is run
// often used for importing definitions, data,
// or changing a server info setting
}
@AfterClass(alwaysRun = true)
public void classTeardown()
{
// gets called after every test in this class is run
// often used for cleaning up test data and
// resetting a server info setting
}
@BeforeMethod(alwaysRun = true)
public void beforeMethod()
{
// gets called before every individual test
// often used for resetting test data
}
@AfterMethod(alwaysRun = true)
public void afterMethod()
{
// gets called after every individual test
// often used for resetting test data
}
Assertions
The point of an automated test case is to perform some action and verify that the expected
behavior happened. For example, a workflow test may create an entry to trigger a set field
action. You need to verify that the value put in that field is correct and TestNG provides a class
to do that: Assert. This class, similar to the class in JUnit, provides many static methods to
compare two values. See http://testng.org/javadocs/org/testng/Assert.html for more information.
There are some types of comparisons that TestNG's Assert class does not handle that are
specific to AR System and the Java API. There is a helper class named AssertHelper in our
framework that provides some helper methods for common tests, like verifying a correct error
code was thrown. Look at the class or use Eclipse's code completion pop-up to see what it
provides.
public MyServerTest()
{
super("MyDefinition.def");
}
If you need to import more than one definition then use the helper method in BaseTest named
importDefinition. If you do then make sure to observe the importTestData parameter in the
run.config file. For example:
@BeforeClass(alwaysRun = true)
public void import()
{
if(AutoConfig.getRunConfig().isImportTestData())
{
importDefinition(primaryServer, true, "File1.def", "File2.def", "File3.def");
}
}
In either case (the constructor or importDefinition method) the BaseTest class will keep track of
the definition files and during the @AfterClass method it will cleanup the objects that were
imported. The BaseTest class will only cleanup the objects if cleanupTestData in the run.config
file is set to true.
Logging
The TestNG framework uses log4j for logging. In the AutoLog class there is a method to retrieve
the logger, getLogger. Once you have that you can log messages depending on their level:
debug, info, warn, error, and fatal. Do not use System.err or System.out to print messages to
the console. Everything that is logged is not only logged to a file but also printed to the console.
Do not use printStackTrace after catching an exception. The log methods allow you to pass an
exception and the logger will print out the stack trace along with the message you provide, for
example:
try
{
...
}
catch(ARException e)
{
// don't fail test, just log and move on
AutoLog.getLogger().info("API call failed, just log and move on", e);
}
Negative tests
To write a proper negative test, where an API call should throw an exception, you need to
include two assertions: a failure if an exception was not thrown, and an assertion that the
correct error code was thrown. In order to help with the second part there is a helper method in
the AssertHelper class named assertErrorCode that will verify that the correct error code was
returned. For example, to verify that submitting a record without a value in the Short Description
field:
try
{
// create entry without a required field
Entry entry = new Entry();
entry.put(Constants.AR_CORE_SUBMITTER, new Value("Demo"));
primaryServer.createEntry("My Test Form", entry);
Assert.fail("API call should have thrown an exception");
}
catch(ARException e)
{
AssertHelper.assertErrorCode(e, ARErrors.AR_ERROR_REQ_VALUE_MISSING);
}
@BeforeClass(alwaysRun = true)
public void setup throws ARException
{
// create group
groupRequestId = TestHelper.createGroup(primaryServer, "ExampleTestGroup", 5123,
Constants.AR_GROUP_TYPE_VIEW,
Constants.AR_GROUP_CATEGORY_REGULAR);
@AfterClass(alwaysRun = true)
public void tearDown()
{
// logout user
testUser.logout();
// delete user
try
{
if(userRequestId != null)
primaryServer.deleteEntry("User", userRequestId, 0);
}
catch(ARException e)
{
String message = "Error while trying to delete user.";
AutoLog.getLogger().warn(message, e);
}
// delete group
try
{
if(groupRequestId!= null)
primaryServer.deleteEntry("Group", groupRequestId, 0);
}
catch(ARException e)
{
String message = "Error while trying to delete group.";
AutoLog.getLogger().warn(message, e);
}
}
Step 1- From Perforce Select the class from which you need to send your test case for review
and right click and select checkout.
Step 2: once you will checkout. You will get one pending change list.
Step 3- right click on the the default change list and select the Edit the default changelist.write
the change list description means the description about your test case. And click on “Save as
Numbered Change list”
Step 4 – you will get the numbered change list. Select it and right click after that select
“SmartBear- Add to Review”
Step 5-it will open the following window click on finish.
Step 6- it will open the browser.enter your adprod credentials.
Step 7- you will get the Following window. You just need to select the reviewer.
Reviewer is the person in which you need to send your code for review.
Step 8- if reviewer will send you suggestion you have to modify the test case as per suggestions
and again send it for review .once reviewer will accept your test case, the last important step is
check in code into perforce
How to check in you testcase Into Perforce.
Step1- select the change list and right click and select “submit” option.it will submit your code.
Question And answers.