{"id":603,"date":"2011-10-26T09:22:00","date_gmt":"2011-10-26T09:22:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/spring-3-testing-with-junit-4-contextconfiguration-and-abstracttransactionaljunit4springcontexttests.html"},"modified":"2012-10-21T20:24:07","modified_gmt":"2012-10-21T20:24:07","slug":"spring-3-testing-with-junit-4","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html","title":{"rendered":"Spring 3 Testing with JUnit 4 &#8211; ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">Looking in the internet for a way to test my Spring 3 application, I found many articles that describe how to test your application by using JUnit. Most of them are incomplete examples that do not really work.<\/p>\n<p>With this article I will try to fill this gap and write a concise yet simple article on how to test a spring 3 application with Junit 4. Ta make it easier to read and go through, I will not use my application which is now quite big, but I will use the sample given from <a href=\"http:\/\/viralpatel.net\/\">viralpatel<\/a>. The link to download the project is <a href=\"http:\/\/viralpatel.net\/blogs\/download\/spring\/spring-3-mvc-series\/Spring3HibernateMaven.zip\">this<\/a>.<\/p>\n<p>Download this application and import it into eclipse.<\/p>\n<p>Execute the following in you db:<\/p>\n<pre class=\"brush:sql\">create database contact;\r\nuse contact;\r\nCREATE TABLE CONTACTS\r\n(\r\n    id              INT PRIMARY KEY AUTO_INCREMENT,\r\n    firstname    VARCHAR(30),\r\n    lastname    VARCHAR(30),\r\n    telephone   VARCHAR(15),\r\n    email         VARCHAR(30),\r\n    created     TIMESTAMP DEFAULT NOW()\r\n);\r\n<\/pre>\n<p>Inside your pom.xml add the following dependencies:<\/p>\n<pre class=\"brush:xml\">&lt;dependency&gt;\r\n &lt;groupId&gt;org.springframework.data&lt;\/groupId&gt;\r\n &lt;artifactId&gt;spring-data-jpa&lt;\/artifactId&gt;\r\n &lt;version&gt;1.0.1.RELEASE&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt;\r\n &lt;groupId&gt;org.junit&lt;\/groupId&gt;\r\n &lt;artifactId&gt;com.springsource.org.junit&lt;\/artifactId&gt;\r\n &lt;version&gt;4.7.0&lt;\/version&gt;\r\n &lt;scope&gt;test&lt;\/scope&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt;\r\n &lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n &lt;artifactId&gt;org.springframework.test&lt;\/artifactId&gt;\r\n &lt;version&gt;${org.springframework.version}&lt;\/version&gt;\r\n &lt;scope&gt;test&lt;\/scope&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt; &lt;groupId&gt;javax.transaction&lt;\/groupId&gt;\r\n &lt;artifactId&gt;com.springsource.javax.transaction&lt;\/artifactId&gt;\r\n &lt;version&gt;1.1.0&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n<\/pre>\n<p>Also add the following for repositories:<\/p>\n<pre class=\"brush:xml\">&lt;repositories&gt;\r\n &lt;repository&gt;\r\n  &lt;id&gt;com.springsource.repository.bundles.release&lt;\/id&gt;\r\n  &lt;name&gt;SpringSource Enterprise Bundle Repository - SpringSource Releases&lt;\/name&gt;\r\n  &lt;url&gt;http:\/\/repository.springsource.com\/maven\/bundles\/release&lt;\/url&gt;\r\n &lt;\/repository&gt;\r\n &lt;repository&gt;\r\n  &lt;id&gt;com.springsource.repository.bundles.external&lt;\/id&gt;\r\n  &lt;name&gt;SpringSource Enterprise Bundle Repository - External Releases&lt;\/name&gt;\r\n  &lt;url&gt;http:\/\/repository.springsource.com\/maven\/bundles\/external&lt;\/url&gt;\r\n &lt;\/repository&gt;\r\n &lt;repository&gt;\r\n  &lt;id&gt;com.springsource.repository.bundles.milestone&lt;\/id&gt;\r\n  &lt;name&gt;SpringSource Enterprise Bundle Repository - SpringSource Milestones&lt;\/name&gt;\r\n  &lt;url&gt;http:\/\/repository.springsource.com\/maven\/bundles\/milestone&lt;\/url&gt;\r\n &lt;\/repository&gt;\r\n &lt;repository&gt;\r\n  &lt;id&gt;com.springsource.repository.bundles.snapshot&lt;\/id&gt;\r\n  &lt;name&gt;SpringSource Enterprise Bundle Repository - Snapshot Releases&lt;\/name&gt;\r\n  &lt;url&gt;http:\/\/repository.springsource.com\/maven\/bundles\/snapshot&lt;\/url&gt;\r\n &lt;\/repository&gt;\r\n &lt;repository&gt;\r\n  &lt;id&gt;repository.springframework.maven.release&lt;\/id&gt;\r\n  &lt;name&gt;Spring Framework Maven Release Repository&lt;\/name&gt;\r\n  &lt;url&gt;http:\/\/maven.springframework.org\/release&lt;\/url&gt;\r\n &lt;\/repository&gt;\r\n &lt;repository&gt;\r\n  &lt;id&gt;repository.springframework.maven.milestone&lt;\/id&gt;\r\n  &lt;name&gt;Spring Framework Maven Milestone Repository&lt;\/name&gt;\r\n  &lt;url&gt;http:\/\/maven.springframework.org\/milestone&lt;\/url&gt;\r\n &lt;\/repository&gt;\r\n &lt;repository&gt;\r\n  &lt;id&gt;repository.springframework.maven.snapshot&lt;\/id&gt;\r\n  &lt;name&gt;Spring Framework Maven Snapshot Repository&lt;\/name&gt;\r\n  &lt;url&gt;http:\/\/maven.springframework.org\/snapshot&lt;\/url&gt;\r\n &lt;\/repository&gt;\r\n &lt;repository&gt;\r\n  &lt;id&gt;jboss&lt;\/id&gt;\r\n  &lt;name&gt;JBoss repository&lt;\/name&gt;\r\n  &lt;url&gt;https:\/\/repository.jboss.org\/nexus\/content\/repositories\/releases&lt;\/url&gt;\r\n &lt;\/repository&gt;\r\n&lt;\/repositories&gt;\r\n<\/pre>\n<p>Under the directory src\/test\/java create the following package:<br \/>\n<span style=\"font-style: italic\">net.viralpatel.contact.form<\/span><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Inside the package you just created create a class called:<br \/>\n<span style=\"font-style: italic\">AbstractContactTests<\/span><\/p>\n<p>Under src\/test\/resources create the following:<br \/>\n<span style=\"font-style: italic\">net\/viralpatel\/contact\/form<\/span><\/p>\n<p>Inside there create the following file:<br \/>\n<span style=\"font-style: italic\">AbstractContactTests-context.xml<\/span><\/p>\n<p>Attention! Make sure that the directories, packages, classes and xml files are created exactly where mentioned above. You will see that the xml file takes the name of the test class plus \u201c-context.xml\u201d and that it is created under the same directory structure. This is important because spring automatically looks for the xml file with the specified name and also under the same directory.<\/p>\n<p>Now insert the following content in the AbstractContactTests class:<\/p>\n<pre class=\"brush:java\">package net.viralpatel.contact.form;\r\n\r\nimport net.viralpatel.contact.dao.ContactDAO;\r\nimport net.viralpatel.contact.service.ContactService;\r\nimport org.junit.Test;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.test.context.ContextConfiguration;\r\nimport org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;\r\n\r\n@ContextConfiguration\r\npublic class AbstractContactTests extends AbstractTransactionalJUnit4SpringContextTests {\r\n @Autowired\r\n protected ContactDAO contact;\r\n @Autowired\r\n protected ContactService contactService;\r\n @Test\r\n public void sampleTest(){\r\n   System.out.println(\"Number of rows is: \" + contactService.listContact().size());\r\n  System.out.println(\"Creating a new contact\");\r\n  Contact cont = new Contact();\r\n  cont.setEmail(\"giannis@gmail.com\");\r\n  cont.setLastname(\"ntantis\");\r\n  cont.setFirstname(\"ioannis\");\r\n  cont.setTelephone(\"00306985587996\");\r\n  System.out.println(\"Before saving contact\");\r\n  contactService.addContact(cont);\r\n  System.out.println(\"After saving contact. Id if contact is: \" + cont.getId());\r\n  System.out.println(\"Number of rows now is: \" + contactService.listContact().size());\r\n }\r\n}\r\n<\/pre>\n<p>The <a href=\"http:\/\/static.springsource.org\/spring\/docs\/3.1.x\/javadoc-api\/org\/springframework\/test\/context\/ContextConfiguration.html\">@ContextConfiguration<\/a> annotation tells spring how to load and configure the application context. We could also tell spring where it would explicitly find the file, e.g. :<\/p>\n<p><i>@ContextConfiguration(locations={\u201cexample\/test-context.xml\u201d}, loader=CustomContextLoader.class)<\/i><\/p>\n<p>By providing no parameters, spring will look for the xml file under the same directory as the package of the class, and for a file named class.name-context.xml (remember the HINT above).<\/p>\n<p>Pay attention that our class extends the <a href=\"http:\/\/static.springsource.org\/spring\/docs\/3.1.x\/javadoc-api\/org\/springframework\/test\/context\/junit4\/AbstractTransactionalJUnit4SpringContextTests.html\">AbstractTransactionalJUnit4SpringContextTests<\/a> from org.springframework.test.context.junit4. By extending this class, we give our methods transactional support at the class level. If we did not do this, and we wanted transactional support, we would have to either annotate our methods with <a href=\"http:\/\/static.springsource.org\/spring\/docs\/3.0.x\/javadoc-api\/org\/springframework\/transaction\/annotation\/Transactional.html\">@Transactional<\/a> or configure our transaction manager with the <a href=\"http:\/\/static.springsource.org\/spring\/docs\/3.1.x\/javadoc-api\/org\/springframework\/test\/context\/transaction\/TransactionConfiguration.html\">@TransactionConfiguration<\/a> annotation.<\/p>\n<p>Inside the AbstractContactTests-context.xml put the following content:<\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n  xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"\r\n  xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\r\n  xmlns:jdbc=\"http:\/\/www.springframework.org\/schema\/jdbc\"\r\n  xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\"\r\n  xsi:schemaLocation=\"\r\n   http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\r\n   http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context.xsd\r\n   http:\/\/www.springframework.org\/schema\/jdbc http:\/\/www.springframework.org\/schema\/jdbc\/spring-jdbc.xsd\r\n   http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx.xsd\"&gt;\r\n &lt;context:property-placeholder location=\"classpath:jdbc.properties\"\/&gt;\r\n &lt;context:annotation-config\/&gt;\r\n &lt;tx:annotation-driven\/&gt;\r\n &lt;bean id=\"dataSource\" class=\"org.apache.commons.dbcp.BasicDataSource\" destroy-method=\"close\"\r\n   p:driverClassName=\"com.mysql.jdbc.Driver\" p:url=\"jdbc:mysql:\/\/localhost:3306\/contact\"\r\n   p:username=\"root\" p:password=\"123456\"\/&gt;\r\n &lt;bean id=\"sessionFactory\"\r\n  class=\"org.springframework.orm.hibernate3.LocalSessionFactoryBean\"&gt;\r\n  &lt;property name=\"dataSource\" ref=\"dataSource\" \/&gt;\r\n  &lt;property name=\"configLocation\"&gt;\r\n   &lt;value&gt;classpath:hibernate.cfg.xml&lt;\/value&gt;\r\n  &lt;\/property&gt;\r\n  &lt;property name=\"configurationClass\"&gt;\r\n   &lt;value&gt;org.hibernate.cfg.AnnotationConfiguration&lt;\/value&gt;\r\n  &lt;\/property&gt;\r\n  &lt;property name=\"hibernateProperties\"&gt;\r\n   &lt;props&gt;\r\n    &lt;prop key=\"hibernate.dialect\"&gt;${jdbc.dialect}&lt;\/prop&gt;\r\n    &lt;prop key=\"hibernate.show_sql\"&gt;true&lt;\/prop&gt;\r\n   &lt;\/props&gt;\r\n  &lt;\/property&gt;\r\n &lt;\/bean&gt;\r\n &lt;bean id=\"transactionManager\" class=\"org.springframework.orm.hibernate3.HibernateTransactionManager\"&gt;\r\n  &lt;property name=\"sessionFactory\" ref=\"sessionFactory\" \/&gt;\r\n &lt;\/bean&gt;\r\n &lt;bean id=\"contactDAO\" class=\"net.viralpatel.contact.dao.ContactDAOImpl\"&gt;&lt;\/bean&gt;\r\n &lt;bean id=\"contactService\" class=\"net.viralpatel.contact.service.ContactServiceImpl\"&gt;&lt;\/bean&gt;\r\n&lt;\/beans&gt;\r\n<\/pre>\n<p>Inside here you will see many definitions which are defined in the spring-servlet.xml. In my example they are the same with spring-servlet.xml, but you could freely alter them. With this, Spring gives the opportunity to create a different data source for example, for the testing process, or even different data source for each test class.<\/p>\n<p>Now execute the AbstractContactTests class as a junit test. You should take the following output:<\/p>\n<pre><code style=\"color: black\">Hibernate: select contact0_.ID as ID0_, contact0_.EMAIL as EMAIL0_, contact0_.FIRSTNAME as FIRSTNAME0_, contact0_.LASTNAME as LASTNAME0_, contact0_.TELEPHONE as TELEPHONE0_ from CONTACTS contact0_\r\nNumber of rows is: 0\r\nCreating a new contact\r\nBefore saving contact\r\nHibernate: insert into CONTACTS (EMAIL, FIRSTNAME, LASTNAME, TELEPHONE) values (?, ?, ?, ?)\r\nAfter saving contact. Id if contact is: 2\r\nHibernate: select contact0_.ID as ID0_, contact0_.EMAIL as EMAIL0_, contact0_.FIRSTNAME as FIRSTNAME0_, contact0_.LASTNAME as LASTNAME0_, contact0_.TELEPHONE as TELEPHONE0_ from CONTACTS contact0_\r\nNumber of rows now is: 1<\/code><\/pre>\n<p>Thats all you need folks. Happy coding and don&#8217;t forget to share! <\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/giannisapi.wordpress.com\/2011\/09\/30\/spring-3-testing-with-junit-4-using-contextconfiguration-and-abstracttransactionaljunit4springcontexttests\/\">Spring 3 Testing with JUnit 4. Using @ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> Ioannis Ntantis at the <a href=\"http:\/\/giannisapi.wordpress.com\/\">Giannisapi blog<\/a>.<\/p>\n<div style=\"margin: 0px\"><strong><i>Related Articles :<\/i><\/strong><\/div>\n<ul>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/rules-in-junit-49-beta-3.html\">Rules in JUnit 4.9 (beta 3)<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/code-coverage-with-unit-integration.html\">Code coverage with unit &amp; integration tests<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/04\/spring-mvc3-hibernate-crud-sample.html\">Spring MVC3 Hibernate CRUD Sample Application<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/08\/integrating-jersey-with-spring.html\">Integrating Jersey with Spring<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/06\/spring-quartz-javamail-tutorial.html\">Spring, Quartz and JavaMail Integration Tutorial<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/spring-declarative-transactions-example.html\">Spring Declarative Transactions Example<\/a>&nbsp;<\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/p\/java-tutorials.html\">Java Tutorials and Android Tutorials list<\/a> <\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Looking in the internet for a way to test my Spring 3 application, I found many articles that describe how to test your application by using JUnit. Most of them are incomplete examples that do not really work. With this article I will try to fill this gap and write a concise yet simple article &hellip;<\/p>\n","protected":false},"author":100,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[274,30],"class_list":["post-603","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-junit","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring 3 Testing with JUnit 4 - ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Looking in the internet for a way to test my Spring 3 application, I found many articles that describe how to test your application by using JUnit. Most\" \/>\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\/2011\/10\/spring-3-testing-with-junit-4.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring 3 Testing with JUnit 4 - ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Looking in the internet for a way to test my Spring 3 application, I found many articles that describe how to test your application by using JUnit. Most\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.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=\"2011-10-26T09:22:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T20:24:07+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=\"Ioannis Dadis\" \/>\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=\"Ioannis Dadis\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.html\"},\"author\":{\"name\":\"Ioannis Dadis\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/d61318841fdb3cc6344ccbc8fbae1e0c\"},\"headline\":\"Spring 3 Testing with JUnit 4 &#8211; ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests\",\"datePublished\":\"2011-10-26T09:22:00+00:00\",\"dateModified\":\"2012-10-21T20:24:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.html\"},\"wordCount\":535,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"JUnit\",\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.html\",\"name\":\"Spring 3 Testing with JUnit 4 - ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2011-10-26T09:22:00+00:00\",\"dateModified\":\"2012-10-21T20:24:07+00:00\",\"description\":\"Looking in the internet for a way to test my Spring 3 application, I found many articles that describe how to test your application by using JUnit. Most\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.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\\\/2011\\\/10\\\/spring-3-testing-with-junit-4.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 3 Testing with JUnit 4 &#8211; ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests\"}]},{\"@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\\\/d61318841fdb3cc6344ccbc8fbae1e0c\",\"name\":\"Ioannis Dadis\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ebb60c8a0c366bddc1a20ad47e065b818a268e35ddbec0e0008eee6a7d78db2?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ebb60c8a0c366bddc1a20ad47e065b818a268e35ddbec0e0008eee6a7d78db2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2ebb60c8a0c366bddc1a20ad47e065b818a268e35ddbec0e0008eee6a7d78db2?s=96&d=mm&r=g\",\"caption\":\"Ioannis Dadis\"},\"sameAs\":[\"http:\\\/\\\/giannisapi.wordpress.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Ioannis-Dadis\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring 3 Testing with JUnit 4 - ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests - Java Code Geeks","description":"Looking in the internet for a way to test my Spring 3 application, I found many articles that describe how to test your application by using JUnit. Most","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\/2011\/10\/spring-3-testing-with-junit-4.html","og_locale":"en_US","og_type":"article","og_title":"Spring 3 Testing with JUnit 4 - ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests - Java Code Geeks","og_description":"Looking in the internet for a way to test my Spring 3 application, I found many articles that describe how to test your application by using JUnit. Most","og_url":"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-10-26T09:22:00+00:00","article_modified_time":"2012-10-21T20:24:07+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":"Ioannis Dadis","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Ioannis Dadis","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html"},"author":{"name":"Ioannis Dadis","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/d61318841fdb3cc6344ccbc8fbae1e0c"},"headline":"Spring 3 Testing with JUnit 4 &#8211; ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests","datePublished":"2011-10-26T09:22:00+00:00","dateModified":"2012-10-21T20:24:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html"},"wordCount":535,"commentCount":3,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["JUnit","Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html","url":"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html","name":"Spring 3 Testing with JUnit 4 - ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2011-10-26T09:22:00+00:00","dateModified":"2012-10-21T20:24:07+00:00","description":"Looking in the internet for a way to test my Spring 3 application, I found many articles that describe how to test your application by using JUnit. Most","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.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\/2011\/10\/spring-3-testing-with-junit-4.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 3 Testing with JUnit 4 &#8211; ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests"}]},{"@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\/d61318841fdb3cc6344ccbc8fbae1e0c","name":"Ioannis Dadis","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2ebb60c8a0c366bddc1a20ad47e065b818a268e35ddbec0e0008eee6a7d78db2?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2ebb60c8a0c366bddc1a20ad47e065b818a268e35ddbec0e0008eee6a7d78db2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2ebb60c8a0c366bddc1a20ad47e065b818a268e35ddbec0e0008eee6a7d78db2?s=96&d=mm&r=g","caption":"Ioannis Dadis"},"sameAs":["http:\/\/giannisapi.wordpress.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Ioannis-Dadis"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/603","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\/100"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=603"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/603\/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=603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}