{"id":1209,"date":"2012-05-25T19:00:00","date_gmt":"2012-05-25T19:00:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/spring-testing-support-with-testng.html"},"modified":"2012-10-22T05:03:01","modified_gmt":"2012-10-22T05:03:01","slug":"spring-testing-support-with-testng","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html","title":{"rendered":"Spring Testing Support with TestNG"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">TestNG is a test framework which is designed to cover all categories of tests: unit, functional, end-to-end, integration, (etc). It includes a lot of features such as flexible test configuration, support for data-driven testing (with @DataProvider), powerful execution model (no more TestSuite) (etc).  <\/p>\n<p>Spring testing support covers very useful and important features for unit and integration testing of spring based applications. The <strong>org.springframework.test.context.testng<\/strong> package provides support classes for TestNG based test cases. This article shows how to test Spring Service layer components by using Spring and TestNG integration. Also next article will show how to test Spring Data Access layer components by using same integration.            <\/p>\n<p><strong>Used Technologies :<\/strong>          <\/p>\n<p>JDK 1.6.0_31<br \/>\nSpring 3.1.1<br \/>\nTestNG 6.4<br \/>\nMaven 3.0.2           <\/p>\n<p><strong>STEP 1 : CREATE MAVEN PROJECT<\/strong>          <\/p>\n<p>A maven project is created as follows. (It can be created by using Maven or IDE Plug-in).           <\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/3.bp.blogspot.com\/-QrcIRkVFpE0\/T76dVRhqhvI\/AAAAAAAAARo\/o3LZ2fSKO80\/s1600\/SpringTestNG.png\"><img decoding=\"async\" border=\"0\" height=\"400\" src=\"http:\/\/3.bp.blogspot.com\/-QrcIRkVFpE0\/T76dVRhqhvI\/AAAAAAAAARo\/o3LZ2fSKO80\/s400\/SpringTestNG.png\" width=\"230\" \/><\/a><\/div>\n<p><strong>STEP 2 : LIBRARIES<\/strong>          <\/p>\n<p>Spring dependencies are added to Maven\u2019 s pom.xml.            <\/p>\n<pre class=\"brush:xml\"> &lt;properties&gt;\r\n  &lt;spring.version&gt;3.1.1.RELEASE&lt;\/spring.version&gt;\r\n &lt;\/properties&gt;\r\n\r\n &lt;dependencies&gt;\r\n        &lt;!-- Spring 3 dependencies --&gt;\r\n        &lt;dependency&gt;\r\n   &lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n   &lt;artifactId&gt;spring-core&lt;\/artifactId&gt;\r\n   &lt;version&gt;${spring.version}&lt;\/version&gt;\r\n  &lt;\/dependency&gt;\r\n\r\n  &lt;dependency&gt;\r\n   &lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n   &lt;artifactId&gt;spring-context&lt;\/artifactId&gt;\r\n   &lt;version&gt;${spring.version}&lt;\/version&gt;\r\n  &lt;\/dependency&gt;\r\n\r\n  &lt;dependency&gt;\r\n            &lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;spring-test&lt;\/artifactId&gt;\r\n            &lt;version&gt;${spring.version}&lt;\/version&gt;\r\n        &lt;\/dependency&gt;\r\n\r\n        &lt;!-- TestNG dependency --&gt;\r\n        &lt;dependency&gt;\r\n   &lt;groupId&gt;org.testng&lt;\/groupId&gt;\r\n   &lt;artifactId&gt;testng&lt;\/artifactId&gt;\r\n   &lt;version&gt;6.4&lt;\/version&gt;\r\n  &lt;\/dependency&gt;\r\n\r\n        &lt;!-- Log4j dependency --&gt;\r\n  &lt;dependency&gt;\r\n   &lt;groupId&gt;log4j&lt;\/groupId&gt;\r\n   &lt;artifactId&gt;log4j&lt;\/artifactId&gt;\r\n   &lt;version&gt;1.2.16&lt;\/version&gt;\r\n  &lt;\/dependency&gt;\r\n\r\n &lt;\/dependencies&gt;\r\n<\/pre>\n<p><strong>STEP 3 : CREATE USER CLASS<\/strong>          <\/p>\n<p>A new User Class is created.           <\/p>\n<pre class=\"brush:java\">package com.otv.user;\r\n\r\n\/**\r\n * User Bean\r\n *\r\n * @author  onlinetechvision.com\r\n * @since   19 May 2012\r\n * @version 1.0.0\r\n *\r\n *\/\r\npublic class User {\r\n\r\n private String id;\r\n private String name;\r\n private String surname;\r\n\r\n \/**\r\n  * Gets User Id\r\n  *\r\n  * @return String id\r\n  *\/\r\n public String getId() {\r\n  return id;\r\n }\r\n\r\n \/**\r\n  * Sets User Id\r\n  *\r\n  * @param String id\r\n  *\/\r\n public void setId(String id) {\r\n  this.id = id;\r\n }\r\n\r\n \/**\r\n  * Gets User Name\r\n  *\r\n  * @return String name\r\n  *\/\r\n public String getName() {\r\n  return name;\r\n }\r\n\r\n \/**\r\n  * Sets User Name\r\n  *\r\n  * @param String name\r\n  *\/\r\n public void setName(String name) {\r\n  this.name = name;\r\n }\r\n\r\n \/**\r\n  * Gets User Surname\r\n  *\r\n  * @return String Surname\r\n  *\/\r\n public String getSurname() {\r\n  return surname;\r\n }\r\n\r\n \/**\r\n  * Sets User Surname\r\n  *\r\n  * @param String surname\r\n  *\/\r\n public void setSurname(String surname) {\r\n  this.surname = surname;\r\n }\r\n\r\n @Override\r\n public String toString() {\r\n  StringBuilder strBuilder = new StringBuilder();\r\n  strBuilder.append(\"Id : \").append(getId());\r\n  strBuilder.append(\", Name : \").append(getName());\r\n  strBuilder.append(\", Surname : \").append(getSurname());\r\n  return strBuilder.toString();\r\n }\r\n\r\n @Override\r\n public int hashCode() {\r\n  final int prime = 31;\r\n  int result = 1;\r\n  result = prime * result + ((id == null) ? 0 : id.hashCode());\r\n  result = prime * result + ((name == null) ? 0 : name.hashCode());\r\n  result = prime * result + ((surname == null) ? 0 : surname.hashCode());\r\n  return result;\r\n }\r\n\r\n @Override\r\n public boolean equals(Object obj) {\r\n  if (this == obj)\r\n   return true;\r\n  if (obj == null)\r\n   return false;\r\n  if (getClass() != obj.getClass())\r\n   return false;\r\n  User other = (User) obj;\r\n  if (id == null) {\r\n   if (other.id != null)\r\n    return false;\r\n  } else if (!id.equals(other.id))\r\n   return false;\r\n  if (name == null) {\r\n   if (other.name != null)\r\n    return false;\r\n  } else if (!name.equals(other.name))\r\n   return false;\r\n  if (surname == null) {\r\n   if (other.surname != null)\r\n    return false;\r\n  } else if (!surname.equals(other.surname))\r\n   return false;\r\n  return true;\r\n }\r\n}\r\n<\/pre>\n<p><strong>STEP 4 : CREATE NonExistentUserException CLASS<\/strong>          <\/p>\n<p>NonExistentUserException Class is created.            <\/p>\n<pre class=\"brush:java\">package com.otv.common.exceptions;\r\n\r\n\/**\r\n * Non Existent User Exception\r\n *\r\n * @author  onlinetechvision.com\r\n * @since   19 May 2012\r\n * @version 1.0.0\r\n *\r\n *\/\r\npublic class NonExistentUserException extends Exception {\r\n\r\n private static final long serialVersionUID = 1L;\r\n\r\n public NonExistentUserException(String message) {\r\n  super(message);\r\n }\r\n}\r\n<\/pre>\n<p><strong>STEP 5 : CREATE ICacheService INTERFACE<\/strong>          <div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>ICacheService Interface representing a cache service interface, is created.            <\/p>\n<pre class=\"brush:java\">package com.otv.cache.service;\r\n\r\nimport java.util.concurrent.ConcurrentHashMap;\r\n\r\nimport com.otv.user.User;\r\n\r\n\/**\r\n * Cache Service Interface\r\n *\r\n * @author  onlinetechvision.com\r\n * @since   19 May 2012\r\n * @version 1.0.0\r\n *\r\n *\/\r\npublic interface ICacheService {\r\n\r\n   \/**\r\n  * Gets User Map\r\n  *\r\n  * @return ConcurrentHashMap User Map\r\n  *\/\r\n ConcurrentHashMap&lt;String, User&gt; getUserMap();\r\n\r\n}\r\n<\/pre>\n<p><strong>STEP 6 : CREATE CacheService CLASS<\/strong>          <\/p>\n<p>CacheService Class is created by implementing ICacheService Interface. It provides access to the remote cache\u2026            <\/p>\n<pre class=\"brush:java\">package com.otv.cache.service;\r\n\r\nimport java.util.concurrent.ConcurrentHashMap;\r\n\r\nimport com.otv.user.User;\r\n\r\n\/**\r\n * Cache Service Implementation\r\n *\r\n * @author  onlinetechvision.com\r\n * @since   19 May 2012\r\n * @version 1.0.0\r\n *\r\n *\/\r\npublic class CacheService implements ICacheService {\r\n\r\n \/\/User Map is injected...\r\n private ConcurrentHashMap&lt;String, User&gt; userMap;\r\n\r\n \/**\r\n  * Gets User Map\r\n  *\r\n  * @return ConcurrentHashMap User Map\r\n  *\/\r\n public ConcurrentHashMap&lt;String, User&gt; getUserMap() {\r\n  return userMap;\r\n }\r\n\r\n \/**\r\n  * Sets User Map\r\n  *\r\n  * @param ConcurrentHashMap User Map\r\n  *\/\r\n public void setUserMap(ConcurrentHashMap&lt;String, User&gt; userMap) {\r\n  this.userMap = userMap;\r\n }\r\n\r\n}\r\n<\/pre>\n<p><strong>STEP 7 : CREATE IUserService INTERFACE<\/strong>          <\/p>\n<p>IUserService Interface representing User Service interface is created.           <\/p>\n<pre class=\"brush:java\">package com.otv.user.service;\r\n\r\nimport java.util.Collection;\r\n\r\nimport com.otv.common.exceptions.NonExistentUserException;\r\nimport com.otv.user.User;\r\n\r\n\/**\r\n *\r\n * User Service Interface\r\n *\r\n * @author  onlinetechvision.com\r\n * @since   19 May 2012\r\n * @version 1.0.0\r\n *\r\n *\/\r\npublic interface IUserService {\r\n\r\n \/**\r\n  * Adds User\r\n  *\r\n  * @param  User user\r\n  * @return boolean whether delete operation is success or not.\r\n  *\/\r\n boolean addUser(User user);\r\n\r\n \/**\r\n  * Deletes User\r\n  *\r\n  * @param  User user\r\n  * @return boolean whether delete operation is success or not.\r\n  *\/\r\n boolean deleteUser(User user);\r\n\r\n \/**\r\n  * Updates User\r\n  *\r\n  * @param  User user\r\n  * @throws NonExistentUserException\r\n  *\/\r\n void updateUser(User user) throws NonExistentUserException;\r\n\r\n \/**\r\n  * Gets User\r\n  *\r\n  * @param  String User Id\r\n  * @return User\r\n  *\/\r\n User getUserById(String id);\r\n\r\n \/**\r\n  * Gets User Collection\r\n  *\r\n  * @return List - User list\r\n  *\/\r\n Collection&lt;User&gt; getUsers();\r\n}\r\n<\/pre>\n<p><strong>STEP 8 : CREATE UserService CLASS<\/strong>          <\/p>\n<p>UserService Class is created by implementing IUserService Interface.           <\/p>\n<pre class=\"brush:java\">package com.otv.user.service;\r\n\r\nimport java.util.Collection;\r\nimport com.otv.cache.service.ICacheService;\r\nimport com.otv.common.exceptions.NonExistentUserException;\r\nimport com.otv.user.User;\r\n\r\n\/**\r\n *\r\n * User Service\r\n *\r\n * @author  onlinetechvision.com\r\n * @since   19 May 2012\r\n * @version 1.0.0\r\n *\r\n *\/\r\npublic class UserService implements IUserService {\r\n\r\n \/\/CacheService is injected...\r\n private ICacheService cacheService;\r\n\r\n \/**\r\n  * Adds User\r\n  *\r\n  * @param  User user\r\n  * @return boolean whether delete operation is success or not.\r\n  *\/\r\n public boolean addUser(User user) {\r\n\r\n  getCacheService().getUserMap().put(user.getId(), user);\r\n  if(getCacheService().getUserMap().get(user.getId()).equals(user)) {\r\n   return true;\r\n  }\r\n\r\n  return false;\r\n }\r\n\r\n \/**\r\n  * Deletes User\r\n  *\r\n  * @param  User user\r\n  * @return boolean whether delete operation is success or not.\r\n  *\/\r\n public boolean deleteUser(User user) {\r\n  User removedUser = getCacheService().getUserMap().remove(user.getId());\r\n  if(removedUser != null) {\r\n   return true;\r\n  }\r\n  return false;\r\n }\r\n\r\n \/**\r\n  * Updates User\r\n  *\r\n  * @param  User user\r\n  * @throws NonExistentUserException\r\n  *\/\r\n public void updateUser(User user) throws NonExistentUserException {\r\n  if(getCacheService().getUserMap().containsKey(user.getId())) {\r\n   getCacheService().getUserMap().put(user.getId(), user);\r\n  } else {\r\n   throw new NonExistentUserException(\"Non Existent User can not update! User : \"+user);\r\n  }\r\n }\r\n\r\n \/**\r\n  * Gets User\r\n  *\r\n  * @param  String User Id\r\n  * @return User\r\n  *\/\r\n public User getUserById(String id) {\r\n  return getCacheService().getUserMap().get(id);\r\n }\r\n\r\n \/**\r\n  * Gets User List\r\n  *\r\n  * @return Collection - Collection of Users\r\n  *\/\r\n public Collection&lt;User&gt; getUsers() {\r\n  return (Collection&lt;User&gt;) getCacheService().getUserMap().values();\r\n }\r\n\r\n \/**\r\n  * Gets Cache Service\r\n  *\r\n  * @return ICacheService - Cache Service\r\n  *\/\r\n public ICacheService getCacheService() {\r\n  return cacheService;\r\n }\r\n\r\n \/**\r\n  * Sets Cache Service\r\n  *\r\n  * @param ICacheService - Cache Service\r\n  *\/\r\n public void setCacheService(ICacheService cacheService) {\r\n  this.cacheService = cacheService;\r\n }\r\n\r\n}\r\n<\/pre>\n<p><strong>STEP 9 : CREATE UserServiceTester CLASS<\/strong>          <\/p>\n<p>User Service Tester Class is created by extending AbstractTestNGSpringContextTests.           <\/p>\n<pre class=\"brush:java\">package com.otv.user.service.test;\r\n\r\nimport junit.framework.Assert;\r\n\r\nimport org.apache.log4j.Logger;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.test.context.ContextConfiguration;\r\nimport org.springframework.test.context.testng.AbstractTestNGSpringContextTests;\r\nimport org.testng.annotations.AfterClass;\r\nimport org.testng.annotations.AfterMethod;\r\nimport org.testng.annotations.AfterTest;\r\nimport org.testng.annotations.BeforeClass;\r\nimport org.testng.annotations.BeforeMethod;\r\nimport org.testng.annotations.BeforeTest;\r\nimport org.testng.annotations.Test;\r\n\r\nimport com.otv.common.exceptions.NonExistentUserException;\r\nimport com.otv.user.User;\r\nimport com.otv.user.service.IUserService;\r\n\r\n\/**\r\n * User Service Tester Class\r\n *\r\n * @author  onlinetechvision.com\r\n * @since   19 May 2012\r\n * @version 1.0.0\r\n *\r\n *\/\r\n@ContextConfiguration(locations={\"classpath:applicationContext.xml\"})\r\npublic class UserServiceTester extends AbstractTestNGSpringContextTests {\r\n\r\n private static Logger logger = Logger.getLogger(UserServiceTester.class);\r\n\r\n @Autowired\r\n private IUserService userService;\r\n\r\n private User firstUser;\r\n private User secondUser;\r\n private User thirdUser;\r\n\r\n \/**\r\n  * Creates Test Users\r\n  *\r\n  *\/\r\n private void createUsers() {\r\n  firstUser = new User();\r\n        firstUser.setId(\"1\");\r\n        firstUser.setName(\"Lionel\");\r\n        firstUser.setSurname(\"Messi\");\r\n\r\n        secondUser = new User();\r\n        secondUser.setId(\"2\");\r\n        secondUser.setName(\"David\");\r\n        secondUser.setSurname(\"Villa\");\r\n\r\n        thirdUser = new User();\r\n        thirdUser.setId(\"3\");\r\n        thirdUser.setName(\"Andres\");\r\n        thirdUser.setSurname(\"Iniesta\");\r\n }\r\n\r\n \/**\r\n  * Asserts that User Properties are not null.\r\n  *\r\n  * @param User\r\n  *\/\r\n private void assertNotNullUserProperties(User user) {\r\n  Assert.assertNotNull(\"User must not be null!\", user);\r\n  Assert.assertNotNull(\"Id must not be null!\", user.getId());\r\n  Assert.assertNotNull(\"Name must not be null!\", user.getName());\r\n  Assert.assertNotNull(\"Surname must not be null!\", user.getSurname());\r\n }\r\n\r\n \/**\r\n  * The annotated method will be run before any test method belonging to the classes\r\n  * inside the &lt;test&gt; tag is run.\r\n  *\r\n  *\/\r\n @BeforeTest\r\n    public void beforeTest() {\r\n  logger.debug(\"BeforeTest method is run...\");\r\n }\r\n\r\n \/**\r\n  * The annotated method will be run before the first test method in the current class\r\n  * is invoked.\r\n  *\r\n  *\/\r\n @BeforeClass\r\n    public void beforeClass() {\r\n  logger.debug(\"BeforeClass method is run...\");\r\n  createUsers();\r\n }\r\n\r\n \/**\r\n  * The annotated method will be run before each test method.\r\n  *\r\n  *\/\r\n @BeforeMethod\r\n    public void beforeMethod() {\r\n  logger.debug(\"BeforeMethod method is run...\");\r\n } \r\n\r\n \/**\r\n  * Tests the process of adding user\r\n  *\r\n  *\/\r\n @Test\r\n public void addUser() {\r\n  assertNotNullUserProperties(firstUser);\r\n  Assert.assertTrue(\"User can not be added! User : \" + firstUser, getUserService().addUser(firstUser));\r\n }\r\n\r\n \/**\r\n  * Tests the process of querying user\r\n  *\r\n  *\/\r\n @Test\r\n public void getUserById() {\r\n  User tempUser = getUserService().getUserById(firstUser.getId());\r\n  assertNotNullUserProperties(tempUser);\r\n  Assert.assertEquals(\"Id is wrong!\", \"1\", tempUser.getId());\r\n  Assert.assertEquals(\"Name is wrong!\", \"Lionel\", tempUser.getName());\r\n  Assert.assertEquals(\"Surname is wrong!\", \"Messi\", tempUser.getSurname());\r\n }\r\n\r\n \/**\r\n  * Tests the process of deleting user\r\n  *\r\n  *\/\r\n @Test\r\n public void deleteUser() {\r\n  assertNotNullUserProperties(secondUser);\r\n  Assert.assertTrue(\"User can not be added! User : \" + secondUser, getUserService().addUser(secondUser));\r\n  Assert.assertTrue(\"User can not be deleted! User : \" + secondUser, getUserService().deleteUser(secondUser));\r\n }\r\n\r\n \/**\r\n  * Tests the process of updating user\r\n  * @throws NonExistentUserException\r\n  *\r\n  *\/\r\n @Test(expectedExceptions = NonExistentUserException.class)\r\n public void updateUser() throws NonExistentUserException {\r\n  getUserService().updateUser(thirdUser);\r\n }\r\n\r\n \/**\r\n  * Test user count\r\n  *\r\n  *\/\r\n @Test\r\n public void getUserCount() {\r\n  Assert.assertEquals(1, getUserService().getUsers().size());\r\n }\r\n\r\n \/**\r\n  * The annotated method will be run after all the test methods in the current class have been run.\r\n  *\r\n  *\/\r\n @AfterClass\r\n    public void afterClass() {\r\n  logger.debug(\"AfterClass method is run...\");\r\n }\r\n\r\n \/**\r\n  * The annotated method will be run after all the test methods belonging to the classes inside the &lt;test&gt; tag have run.\r\n  *\r\n  *\/\r\n @AfterTest\r\n    public void afterTest() {\r\n  logger.debug(\"AfterTest method is run...\");\r\n }\r\n\r\n \/**\r\n  * The annotated method will be run after each test method.\r\n  *\r\n  *\/\r\n @AfterMethod\r\n    public void afterMethod() {\r\n  logger.debug(\"AfterMethod method is run...\");\r\n }\r\n\r\n \/**\r\n  * Gets User Service\r\n  *\r\n  * @return IUserService User Service\r\n  *\/\r\n public IUserService getUserService() {\r\n  return userService;\r\n }\r\n\r\n \/**\r\n  * Sets User Service\r\n  *\r\n  * @param IUserService User Service\r\n  *\/\r\n public void setUserService(IUserService userService) {\r\n  this.userService = userService;\r\n }\r\n\r\n}\r\n<\/pre>\n<p><strong>STEP 10 : CREATE applicationContext.xml<\/strong>          <\/p>\n<p>Application Context is created as follows :           <\/p>\n<pre class=\"brush:xml\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n    xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n    xsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/beans\r\n\r\nhttp:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.0.xsd\"&gt;\r\n\r\n &lt;!-- User Map Declaration --&gt;\r\n &lt;bean id=\"UserMap\" class=\"java.util.concurrent.ConcurrentHashMap\" \/&gt;\r\n\r\n &lt;!-- Cache Service Declaration --&gt;\r\n &lt;bean id=\"CacheService\" class=\"com.otv.cache.service.CacheService\"&gt;\r\n  &lt;property name=\"userMap\" ref=\"UserMap\"\/&gt;\r\n &lt;\/bean&gt;\r\n\r\n &lt;!-- User Service Declaration --&gt;\r\n &lt;bean id=\"UserService\" class=\"com.otv.user.service.UserService\"&gt;\r\n    &lt;property name=\"cacheService\" ref=\"CacheService\"\/&gt;\r\n &lt;\/bean&gt;\r\n&lt;\/beans&gt;\r\n<\/pre>\n<p><strong>STEP 11 : RUN PROJECT <\/strong>          <\/p>\n<p>In this article, TestNG Eclipse Plugin has been used. If you use Eclipse, it can be downloaded via <strong><a href=\"http:\/\/testng.org\/doc\/download.html\" target=\"_blank\" title=\"TestNG download page\">TestNG download page<\/a><\/strong>          <\/p>\n<p>If <strong>UserServiceTester<\/strong> is run, results of the test cases are shown as follows :           <\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/2.bp.blogspot.com\/-BdGelXXmOl8\/T76d5s9YctI\/AAAAAAAAARw\/jt56edV-KrA\/s1600\/SpringTestNG_Results.png\"><img decoding=\"async\" border=\"0\" height=\"96\" src=\"http:\/\/2.bp.blogspot.com\/-BdGelXXmOl8\/T76d5s9YctI\/AAAAAAAAARw\/jt56edV-KrA\/s400\/SpringTestNG_Results.png\" width=\"400\" \/><\/a><\/div>\n<p><strong>STEP 12 : DOWNLOAD<\/strong>          <\/p>\n<p><a href=\"http:\/\/www.onlinetechvision.com\/wp-content\/uploads\/2012\/05\/OTV_SpringTestNG1.zip\">OTV_SpringTestNG<\/a>          <\/p>\n<p><strong>REFERENCES :<\/strong><br \/>\n<a href=\"http:\/\/static.springsource.org\/spring\/docs\/current\/spring-framework-reference\/html\/testing.html#testcontext-framework\" target=\"_blank\" title=\"Spring Testing Support\">Spring Testing Support<\/a><br \/>\n<a href=\"http:\/\/testng.org\/doc\/index.html\" target=\"_blank\" title=\"TestNG Reference\">TestNG Reference<\/a><\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/www.onlinetechvision.com\/?p=589\">Spring Testing Support with TestNG <\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> Eren Avsarogullari at the <a href=\"http:\/\/www.onlinetechvision.com\/\">Online Technology Vision<\/a> blog.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>TestNG is a test framework which is designed to cover all categories of tests: unit, functional, end-to-end, integration, (etc). It includes a lot of features such as flexible test configuration, support for data-driven testing (with @DataProvider), powerful execution model (no more TestSuite) (etc). Spring testing support covers very useful and important features for unit and &hellip;<\/p>\n","protected":false},"author":158,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30,273,342],"class_list":["post-1209","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring","tag-testing","tag-testng"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring Testing Support with TestNG - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"TestNG is a test framework which is designed to cover all categories of tests: unit, functional, end-to-end, integration, (etc). It includes a lot of\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Testing Support with TestNG - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"TestNG is a test framework which is designed to cover all categories of tests: unit, functional, end-to-end, integration, (etc). It includes a lot of\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2012-05-25T19:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-22T05:03:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Eren Avsarogullari\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eren Avsarogullari\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html\"},\"author\":{\"name\":\"Eren Avsarogullari\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/65e6e57c730ae5ade3adbadd483553bd\"},\"headline\":\"Spring Testing Support with TestNG\",\"datePublished\":\"2012-05-25T19:00:00+00:00\",\"dateModified\":\"2012-10-22T05:03:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html\"},\"wordCount\":314,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\",\"Testing\",\"TestNG\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html\",\"name\":\"Spring Testing Support with TestNG - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2012-05-25T19:00:00+00:00\",\"dateModified\":\"2012-10-22T05:03:01+00:00\",\"description\":\"TestNG is a test framework which is designed to cover all categories of tests: unit, functional, end-to-end, integration, (etc). It includes a lot of\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/05\\\/spring-testing-support-with-testng.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Spring Testing Support with TestNG\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/65e6e57c730ae5ade3adbadd483553bd\",\"name\":\"Eren Avsarogullari\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d90f2a1d9c2144dd49935d6c84d5c3aa0832793a522148f397bda79bd8e04c16?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d90f2a1d9c2144dd49935d6c84d5c3aa0832793a522148f397bda79bd8e04c16?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d90f2a1d9c2144dd49935d6c84d5c3aa0832793a522148f397bda79bd8e04c16?s=96&d=mm&r=g\",\"caption\":\"Eren Avsarogullari\"},\"sameAs\":[\"http:\\\/\\\/www.onlinetechvision.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Eren-Avsarogullari\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Testing Support with TestNG - Java Code Geeks","description":"TestNG is a test framework which is designed to cover all categories of tests: unit, functional, end-to-end, integration, (etc). It includes a lot of","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html","og_locale":"en_US","og_type":"article","og_title":"Spring Testing Support with TestNG - Java Code Geeks","og_description":"TestNG is a test framework which is designed to cover all categories of tests: unit, functional, end-to-end, integration, (etc). It includes a lot of","og_url":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2012-05-25T19:00:00+00:00","article_modified_time":"2012-10-22T05:03:01+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Eren Avsarogullari","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Eren Avsarogullari","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html"},"author":{"name":"Eren Avsarogullari","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/65e6e57c730ae5ade3adbadd483553bd"},"headline":"Spring Testing Support with TestNG","datePublished":"2012-05-25T19:00:00+00:00","dateModified":"2012-10-22T05:03:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html"},"wordCount":314,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring","Testing","TestNG"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html","url":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html","name":"Spring Testing Support with TestNG - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2012-05-25T19:00:00+00:00","dateModified":"2012-10-22T05:03:01+00:00","description":"TestNG is a test framework which is designed to cover all categories of tests: unit, functional, end-to-end, integration, (etc). It includes a lot of","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2012\/05\/spring-testing-support-with-testng.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Spring Testing Support with TestNG"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/65e6e57c730ae5ade3adbadd483553bd","name":"Eren Avsarogullari","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d90f2a1d9c2144dd49935d6c84d5c3aa0832793a522148f397bda79bd8e04c16?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d90f2a1d9c2144dd49935d6c84d5c3aa0832793a522148f397bda79bd8e04c16?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d90f2a1d9c2144dd49935d6c84d5c3aa0832793a522148f397bda79bd8e04c16?s=96&d=mm&r=g","caption":"Eren Avsarogullari"},"sameAs":["http:\/\/www.onlinetechvision.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Eren-Avsarogullari"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/1209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/158"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=1209"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/1209\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=1209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=1209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=1209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}