{"id":51261,"date":"2017-11-06T11:00:35","date_gmt":"2017-11-06T09:00:35","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=51261"},"modified":"2019-03-20T13:44:07","modified_gmt":"2019-03-20T11:44:07","slug":"junit-httpunit-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/","title":{"rendered":"JUnit HttpUnit Example"},"content":{"rendered":"<p>Hello, in this example we shall show you how you can make a use of the JUnit HTTUnit to test web applications. In this example, we will build a small web application and test it using HTTPUnit. This example will show you how you can achieve a browser specific behaviour&nbsp;with HTTPUnit library like sending requests to the server and receiving response from the server.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;\n<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dt><a href=\"#junithttpunitexample\">2. JUnit HttpUnit Example<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#toolsused\">2.1 Tools Used<\/a><\/dt>\n<dt><a href=\"#projectstructure\">2.2 Project Structure<\/a><\/dt>\n<dt><a href=\"#projectcreation\">2.3 Project Creation<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#applicationbuilding\">3. Application Building<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#mavenDependencies\">3.1 Maven Dependencies<\/a><\/dt>\n<dt><a href=\"#javaClassCreation\">3.2 Java Class Creation<\/a><\/dt>\n<dt><a href=\"#mavenbuild\">3.3 Maven build<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#Runapplication\">4. Run application as spring boot app<\/a><\/dt>\n<dt><a href=\"#projectdemo\">5. Project Demo<\/a><\/dt>\n<dt><a href=\"#conclusion\">6. Conclusion<\/a><\/dt>\n<dt><a href=\"#download\">7. Download the project<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"introduction\"><\/a>1. Introduction<\/h2>\n<p>HttpUnit is an open source test framework for web applications which can provide browser specific behaviour like sending request to&nbsp;the server and receiving response from the server including form submission, basic&nbsp;http authentication, cookies and automatic page redirection.<\/p>\n<p>A website has several forms with multiple textboxes, dropdowns, radio buttons, submit buttons, links etc. In order to test a form submission, you test whether dropdowns are populated with the desired values, all the controls are set with their default values ,if any, and submit buttons redirect the user to their desired page. Testing a form is one of the many test cases for a website that can be tested using Httpunit.<\/p>\n<h2><a name=\"junithttpunitexample\"><\/a>2. JUnit HttpUnit Example<\/h2>\n<p>Here is a step-by-step guide to test your web application using HTTPUnit.<\/p>\n<h3><a name=\"toolsused\"><\/a>2.1 Tools Used<\/h3>\n<p>We are using Spring sts 3.9, JDK 8, HttpUnit 1.7.<\/p>\n<h3><a name=\"projectstructure\"><\/a>2.2 Project Structure<\/h3>\n<p>The following image of the final project structure shows where I should create the required files and folders .<\/p>\n<p><figure id=\"attachment_51588\" aria-describedby=\"caption-attachment-51588\" style=\"width: 427px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/FinalProject.jpg\"><img decoding=\"async\" class=\"wp-image-51588 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/FinalProject.jpg\" alt=\"\" width=\"427\" height=\"701\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/FinalProject.jpg 427w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/FinalProject-183x300.jpg 183w\" sizes=\"(max-width: 427px) 100vw, 427px\" \/><\/a><figcaption id=\"caption-attachment-51588\" class=\"wp-caption-text\">Fig.1: Project Structure<\/figcaption><\/figure><\/p>\n<h3><a name=\"projectcreation\"><\/a>2.3 Project Creation<\/h3>\n<p>This section will demonstrate on how to create a Java-based Maven project in Spring sts. In spring sts go to <code>File--&gt;New--&gt;Maven Project.<\/code><\/p>\n<p><figure id=\"attachment_51596\" aria-describedby=\"caption-attachment-51596\" style=\"width: 713px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateMavenProjectNew.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51596\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateMavenProjectNew.jpg\" alt=\"\" width=\"713\" height=\"516\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateMavenProjectNew.jpg 713w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateMavenProjectNew-300x217.jpg 300w\" sizes=\"(max-width: 713px) 100vw, 713px\" \/><\/a><figcaption id=\"caption-attachment-51596\" class=\"wp-caption-text\">Fig.2: Create Maven Project<\/figcaption><\/figure><\/p>\n<p>In the new Maven Project window, it will ask you to select a project location. By default \u2018Use default workspace location\u2018 is selected. Just click on next button to proceed.<\/p>\n<p><figure id=\"attachment_51537\" aria-describedby=\"caption-attachment-51537\" style=\"width: 855px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/mavenprojectStep2-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51537\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/mavenprojectStep2-1.jpg\" alt=\"\" width=\"855\" height=\"546\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/mavenprojectStep2-1.jpg 855w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/mavenprojectStep2-1-300x192.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/mavenprojectStep2-1-768x490.jpg 768w\" sizes=\"(max-width: 855px) 100vw, 855px\" \/><\/a><figcaption id=\"caption-attachment-51537\" class=\"wp-caption-text\">Fig.3: Project details<\/figcaption><\/figure><\/p>\n<p>Select the archetype for web app.<\/p>\n<p><figure id=\"attachment_51548\" aria-describedby=\"caption-attachment-51548\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Archetypeselection.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51548\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Archetypeselection.jpg\" alt=\"\" width=\"800\" height=\"509\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Archetypeselection.jpg 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Archetypeselection-300x191.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Archetypeselection-768x489.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-51548\" class=\"wp-caption-text\">Fig.4: ArcheType Selection<\/figcaption><\/figure><\/p>\n<p>Enter the group details and the artifact id for the project as shown. The version number will be by default: 0.0.1-SNAPSHOT.<\/p>\n<p><figure id=\"attachment_51552\" aria-describedby=\"caption-attachment-51552\" style=\"width: 606px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ArchetypeParameters.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51552\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ArchetypeParameters.jpg\" alt=\"\" width=\"606\" height=\"743\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ArchetypeParameters.jpg 606w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ArchetypeParameters-245x300.jpg 245w\" sizes=\"(max-width: 606px) 100vw, 606px\" \/><\/a><figcaption id=\"caption-attachment-51552\" class=\"wp-caption-text\">Fig.5: ArcheType Parameters<\/figcaption><\/figure><\/p>\n<p>Click on finish and a maven project will be created with an initial draft of <code>pom.xml<\/code> with the following details:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\nxsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/maven-v4_0_0.xsd\"&gt;\n&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n&lt;groupId&gt;com.junit&lt;\/groupId&gt;\n&lt;artifactId&gt;httpunitsample&lt;\/artifactId&gt;\n&lt;packaging&gt;war&lt;\/packaging&gt;\n&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\n&lt;\/project&gt;\n<\/pre>\n<p>We can now start adding dependency to this pom.xml for our web application and <code>httpunit<\/code>. We will be building this web application using spring boot, so lets start!!!<\/p>\n<h2><a name=\"applicationbuilding\"><\/a>3. Application Building<\/h2>\n<p>Below are the steps involved in developing this application.<\/p>\n<h3><a name=\"mavenDependencies\"><\/a>3.1 Maven Dependencies<\/h3>\n<p><span style=\"text-decoration: underline;\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n  xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/maven-v4_0_0.xsd\"&gt;\n  &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n  &lt;groupId&gt;com.junit&lt;\/groupId&gt;\n  &lt;artifactId&gt;httpunitsample&lt;\/artifactId&gt;\n  &lt;packaging&gt;war&lt;\/packaging&gt;\n  &lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\n    &lt;properties&gt;\n    &lt;java.version&gt;1.8&lt;\/java.version&gt;\n  &lt;\/properties&gt;\n  &lt;parent&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;\n    &lt;version&gt;1.5.4.RELEASE&lt;\/version&gt;\n  &lt;\/parent&gt;\n  &lt;dependencies&gt;\n    &lt;dependency&gt;\n      &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n      &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n            &lt;!-- JSTL tag lib --&gt;\n    &lt;dependency&gt;\n      &lt;groupId&gt;javax.servlet.jsp.jstl&lt;\/groupId&gt;\n      &lt;artifactId&gt;javax.servlet.jsp.jstl-api&lt;\/artifactId&gt;\n      &lt;version&gt;1.2.1&lt;\/version&gt;\n    &lt;\/dependency&gt;\n\n    &lt;dependency&gt;\n      &lt;groupId&gt;taglibs&lt;\/groupId&gt;\n      &lt;artifactId&gt;standard&lt;\/artifactId&gt;\n      &lt;version&gt;1.1.2&lt;\/version&gt;\n    &lt;\/dependency&gt;\n             &lt;!-- Tomcat for JSP rendering --&gt;\n    &lt;dependency&gt;\n      &lt;groupId&gt;org.apache.tomcat.embed&lt;\/groupId&gt;\n      &lt;artifactId&gt;tomcat-embed-jasper&lt;\/artifactId&gt;\n      &lt;scope&gt;provided&lt;\/scope&gt;\n    &lt;\/dependency&gt;\n            &lt;!--\"https:\/\/mvnrepository.com\/artifact\/httpunit\/httpunit\"--&gt;\n\t&lt;dependency&gt;\n      &lt;groupId&gt;httpunit&lt;\/groupId&gt;\n      &lt;artifactId&gt;httpunit&lt;\/artifactId&gt;\n      &lt;version&gt;1.7&lt;\/version&gt;\n      &lt;scope&gt;test&lt;\/scope&gt;\n\t&lt;\/dependency&gt;\n             &lt;!-- dependency for js.jar --&gt;\n\t&lt;dependency&gt;\n      &lt;groupId&gt;rhino&lt;\/groupId&gt;\n      &lt;artifactId&gt;js&lt;\/artifactId&gt;\n      &lt;version&gt;1.7R2&lt;\/version&gt;\n\t&lt;\/dependency&gt;\n\t&lt;dependency&gt;\n      &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n      &lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;\n      &lt;scope&gt;test&lt;\/scope&gt;\n      &lt;version&gt;1.5.3.RELEASE&lt;\/version&gt;\n\t&lt;\/dependency&gt;\n  &lt;\/dependencies&gt;\n  &lt;build&gt;\n    &lt;plugins&gt;\n      &lt;plugin&gt;\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-boot-maven-plugin&lt;\/artifactId&gt;\n      &lt;\/plugin&gt;\n    &lt;\/plugins&gt;\n  &lt;\/build&gt;\n&lt;\/project&gt;\n<\/pre>\n<p><code>Httpunit jar<\/code> and <code>js.jar<\/code> are the two dependencies required to test this web application using HTTPUnit. We are building this web application using spring boot, hence we have added all the spring boot related dependencies along with Tomcat dependency to enable the embedded Tomcat container.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h3><a name=\"javaClassCreation\"><\/a>3.2 Java Class Creation<\/h3>\n<p>Let\u2019s create the required Java files. Right-click on <code>src\/main\/java<\/code> folder, <code>New -&gt; Package<\/code>.<\/p>\n<p><figure id=\"attachment_51555\" aria-describedby=\"caption-attachment-51555\" style=\"width: 750px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/JavaPkgCreation.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51555\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/JavaPkgCreation.jpg\" alt=\"\" width=\"750\" height=\"380\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/JavaPkgCreation.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/JavaPkgCreation-300x152.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption id=\"caption-attachment-51555\" class=\"wp-caption-text\">Fig.6: Java Package Creation<\/figcaption><\/figure><\/p>\n<p>A new pop window will open where we will enter the package name as: <code>com.httpunitsample.controller<\/code>.<\/p>\n<p><figure id=\"attachment_51557\" aria-describedby=\"caption-attachment-51557\" style=\"width: 750px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/JavaPkgCreation2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51557\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/JavaPkgCreation2.jpg\" alt=\"\" width=\"750\" height=\"458\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/JavaPkgCreation2.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/JavaPkgCreation2-300x183.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption id=\"caption-attachment-51557\" class=\"wp-caption-text\">Fig.7: Java Package creation for controller<\/figcaption><\/figure><\/p>\n<p>Following the above two steps for package creation, create two more packages for form and a main application class i.e <code>com.httpunitsample.form<\/code> and <code>com.httpunitsample.main<\/code>.<\/p>\n<p>Once the package is created, we now need to create the implementation classes. Right-click on the newly created package, <code>New -&gt; Class<\/code>.<\/p>\n<p><figure id=\"attachment_51565\" aria-describedby=\"caption-attachment-51565\" style=\"width: 855px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Javaclasscreation.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51565\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Javaclasscreation.jpg\" alt=\"\" width=\"855\" height=\"580\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Javaclasscreation.jpg 855w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Javaclasscreation-300x204.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Javaclasscreation-768x521.jpg 768w\" sizes=\"(max-width: 855px) 100vw, 855px\" \/><\/a><figcaption id=\"caption-attachment-51565\" class=\"wp-caption-text\">Fig.8: Java class creation<\/figcaption><\/figure><\/p>\n<p>A new pop window will open, enter file name as: <code>RegistrationController<\/code>. A new controller class will be created inside the package: <code>com.httpunitsample.controller<\/code>.<\/p>\n<p><figure id=\"attachment_51567\" aria-describedby=\"caption-attachment-51567\" style=\"width: 855px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Javaclasscreation2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51567\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Javaclasscreation2.jpg\" alt=\"\" width=\"855\" height=\"507\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Javaclasscreation2.jpg 855w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Javaclasscreation2-300x178.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Javaclasscreation2-768x455.jpg 768w\" sizes=\"(max-width: 855px) 100vw, 855px\" \/><\/a><figcaption id=\"caption-attachment-51567\" class=\"wp-caption-text\">Fig.9: Java controller creation<\/figcaption><\/figure><\/p>\n<p>Following the above steps for class creation, create a class for <code>RegistrationForm.java<\/code> and <code>Main.java<\/code> under the package <code>com.httpunitsample.form<\/code> and <code>com.httpunitsample.main<\/code> respectively.<\/p>\n<p>Now, lets create a <code>views<\/code> folder under <code>WEB-INF<\/code> for jsps as shown below.<\/p>\n<p><figure id=\"attachment_51570\" aria-describedby=\"caption-attachment-51570\" style=\"width: 850px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ViewFolder.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51570\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ViewFolder.jpg\" alt=\"\" width=\"850\" height=\"598\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ViewFolder.jpg 850w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ViewFolder-300x211.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ViewFolder-768x540.jpg 768w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/a><figcaption id=\"caption-attachment-51570\" class=\"wp-caption-text\">Fig.10: View folder for jsp<\/figcaption><\/figure><\/p>\n<p>Create a <code>Registration.jsp<\/code> under the <code>views<\/code> folder.<\/p>\n<p><figure id=\"attachment_51572\" aria-describedby=\"caption-attachment-51572\" style=\"width: 750px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/JspCreation.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51572\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/JspCreation.jpg\" alt=\"\" width=\"750\" height=\"645\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/JspCreation.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/JspCreation-300x258.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption id=\"caption-attachment-51572\" class=\"wp-caption-text\">Fig.11: Jsp file creation<\/figcaption><\/figure><\/p>\n<p>Following the above steps create another <code>Hello.jsp<\/code> under the <code>WEB-INF\/views<\/code> folder.<\/p>\n<p>Lets create a <code>application.properties<\/code> file under <code>src\/main\/resources<\/code> for jsp views to be resolved .<\/p>\n<p><figure id=\"attachment_51574\" aria-describedby=\"caption-attachment-51574\" style=\"width: 700px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ApplicationProp.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51574\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ApplicationProp.jpg\" alt=\"\" width=\"700\" height=\"596\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ApplicationProp.jpg 700w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ApplicationProp-300x255.jpg 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/a><figcaption id=\"caption-attachment-51574\" class=\"wp-caption-text\">Fig.12: Application property file<\/figcaption><\/figure><\/p>\n<p>Below is the code for the classes defined above.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>RegistrationController.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.httpunitsample.controller;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport org.springframework.stereotype.Controller;\nimport org.springframework.ui.Model;\nimport org.springframework.web.bind.annotation.RequestMapping;\n\nimport com.httpunitsample.form.RegistrationForm;\n\n@Controller\npublic class RegistrationController {\n\n\t@RequestMapping(value = \"\/registrationForm\")\n    public String registration(Model model) {\n\t\tRegistrationForm registrationForm=new RegistrationForm();\n\t\tList countryList=new ArrayList();\n\t\tcountryList.add(\"America\");\n\t\tcountryList.add(\"India\");\n        model.addAttribute(\"countryList\",countryList);\n        List genderList=new ArrayList();\n        genderList.add(\"Female\");\n        genderList.add(\"Male\");\n        genderList.add(\"Dont want to say\");\n        model.addAttribute(\"genderList\", genderList);\n        \/\/Set default value in gender list dropdown.\n        registrationForm.setGender(\"Dont want to say\");\n        model.addAttribute(\"registrationForm\", registrationForm);\n        return \"Registration\";\n\t}\n\t\n\t@RequestMapping(value = \"\/registrationSubmit\")\n    public String registerUser(RegistrationForm registrationForm,Model model) {\n\t\tmodel.addAttribute(\"name\",registrationForm.getName());\n        return \"Hello\";\n\t}\n}\n\n<\/pre>\n<p>In the above controller class, I have defined two methods:<\/p>\n<ol>\n<li><code>registration<\/code> &#8211; This method returns a registration form set with default values.<\/li>\n<li><code>registerUser<\/code> &#8211; This method returns a hello page to the user, populated with the registered username.<\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\"><em>RegistrationForm.java<\/em><\/span>[ulp id=&#8217;ODQaBEw1BIbHApZq&#8217;]<\/p>\n<pre class=\"brush:java\">package com.httpunitsample.form;\n\npublic class RegistrationForm {\n\n\tprivate int id;\n\tprivate String name;\n\tprivate String gender;\n\tprivate String countryId;\n\n\tpublic int getId() {\n\t\treturn id;\n\t}\n\n\tpublic void setId(int id) {\n\t\tthis.id = id;\n\t}\n\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n\n\tpublic String getGender() {\n\t\treturn gender;\n\t}\n\n\tpublic void setGender(String gender) {\n\t\tthis.gender = gender;\n\t}\n\n\tpublic String getCountryId() {\n\t\treturn countryId;\n\t}\n\n\tpublic void setCountryId(String countryId) {\n\t\tthis.countryId = countryId;\n\t}\n\n}\n\n<\/pre>\n<p>Above is the defined form that will be used for user registration.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Main.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.httpunitsample.main;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.context.annotation.ComponentScan;\n\n@ComponentScan(\"com.httpunitsample\")\n@SpringBootApplication\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t      SpringApplication.run(Main.class, args);\n\t   }\n}\n\n<\/pre>\n<p><code>Main.java<\/code> is the main class that will be called on running the spring boot application.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Hello.jsp<\/em><\/span><\/p>\n<pre class=\"brush:java\">&lt;%@ page language=\"java\" contentType=\"text\/html; charset=ISO-8859-1\" pageEncoding=\"ISO-8859-1\"%&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=ISO-8859-1\"&gt;\n&lt;title&gt;HTTPUnit&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;h2&gt;Thank you for registration ${name}&lt;\/h2&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<p><code>Hello.jsp<\/code> page is shown on successful registration with registered username.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Registration.jsp<\/em><\/span><\/p>\n<pre class=\"brush:java\">&lt;%@ taglib prefix=\"spring\" uri=\"http:\/\/www.springframework.org\/tags\" %&gt;\n&lt;%@ taglib prefix=\"form\" uri=\"http:\/\/www.springframework.org\/tags\/form\" %&gt;\n&lt;%@ taglib prefix=\"c\" uri=\"http:\/\/java.sun.com\/jsp\/jstl\/core\"%&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n    &lt;title&gt;Create an account&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;h1&gt;Welcome to httpunit example registration&lt;\/h1&gt;\n&lt;div class=\"container\"&gt;\n    &lt;form:form method=\"POST\" commandName=\"registrationForm\" action=\"registrationSubmit\"&gt;\n        &lt;spring:bind path=\"name\"&gt;\n                &lt;form:input type=\"text\" path=\"name\"&gt;&lt;\/form:input&gt;\n        &lt;\/spring:bind&gt;\n\n        &lt;spring:bind path=\"gender\"&gt;\n                &lt;form:select path=\"gender\" &gt;\n                 &lt;c:forEach items=\"${genderList}\" var=\"gender\"&gt;\n                 &lt;c:choose&gt;\n\t\t\t\t\t&lt;c:when test=\"${registrationForm.gender eq gender}\"&gt;\n\t\t\t\t\t&lt;option value=\"${gender}\" selected =\"selected\"&gt;&lt;c:out value=\"${gender}\"\/&gt;&lt;\/option&gt;\n\t\t\t\t\t&lt;\/c:when&gt;\n\t\t\t\t\t&lt;c:otherwise&gt;\n\t\t\t\t\t&lt;option value=\"${gender}\"&gt;&lt;c:out value=\"${gender}\" \/&gt;&lt;\/option&gt;\n\t\t\t\t\t&lt;\/c:otherwise&gt;\n\t\t\t\t\t&lt;\/c:choose&gt;\n                 &lt;\/c:forEach&gt;\n                 &lt;\/form:select&gt;\n        &lt;\/spring:bind&gt;\n\n       &lt;spring:bind path=\"countryId\"&gt;\n                &lt;form:select path=\"countryId\" items=\"${countryList}\" \/&gt;\n        &lt;\/spring:bind&gt;\n\n        &lt;button type=\"submit\"&gt;Submit&lt;\/button&gt;\n    &lt;\/form:form&gt;\n\n&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<p><code>Registration.jsp<\/code> page is shown to the user for registration with default values gender list.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>application.properties<\/em><\/span><\/p>\n<pre class=\"brush:java\">spring.mvc.view.prefix = \/WEB-INF\/views\/\nspring.mvc.view.suffix = .jsp\n<\/pre>\n<p>Let us write a test class to test our controller under the package <code>com.httpunitsample.controllertest<\/code>.<\/p>\n<p>We achieved browser specific behaviour through class <code>WebConversation.java<\/code> in Httpunit jar. We sent various requests under test and we received corresponding response for such requests. We then examined these response further.<\/p>\n<p>In my below test controller, I have written two test methods to test the following functionalities:<\/p>\n<ol>\n<li>The registration method in controller returns a registration form with default value for gender list and country dropdown lists with all the required values.<\/li>\n<li><code>RegisterUser<\/code> method in controller, sets the registered name and redirects to hello jsp page. Using <code>httpunit<\/code>, I test if user is redirected to the desired hello page or not.<\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\"><em>RegistrationControllerTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.httpunitsample.controllertest;\n\nimport static org.hamcrest.CoreMatchers.containsString;\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertThat;\nimport java.io.IOException;\nimport org.junit.Test;\nimport org.junit.runner.RunWith;\nimport org.springframework.test.context.junit4.SpringRunner;\nimport org.xml.sax.SAXException;\nimport com.meterware.httpunit.WebConversation;\nimport com.meterware.httpunit.WebForm;\nimport com.meterware.httpunit.WebResponse;\n\n@RunWith(SpringRunner.class) \npublic class RegistrationControllerTest {\n\n\t\t@Test\n\t\tpublic void registrationTest() throws IOException, SAXException {\n\t\t\t WebConversation wc = new WebConversation();\n\t\t\t WebResponse   resp = wc.getResponse( \"http:\/\/localhost:8080\/registrationForm\" );\n\t\t\t WebForm form = resp.getForms()[0];\n\t\t\t assertEquals( \"\", form.getParameterValue( \"name\" ) );\n\t\t\t assertEquals( \"Dont want to say\",       form.getParameterValue( \"gender\" ) );\n\t\t\t assertEquals( \"America\",      form.getParameterValue( \"countryId\" ) );\n\t\t}\n\t\t\n\t\t@Test\n\t\tpublic void registerUserTest() throws IOException, SAXException {\n\t\t\t WebConversation wc = new WebConversation();\n\t\t\t WebResponse   resp = wc.getResponse( \"http:\/\/localhost:8080\/registrationForm\" );\n\t\t\t WebForm form = resp.getForms()[0];\n\t\t\t form.setParameter(\"name\", \"Gaurav\" );\n\t\t\t form.setParameter(\"gender\", \"Male\");\n\t\t\t form.setParameter(\"countryId\", \"India\");\n\t\t\t WebResponse response=form.submit();\n\t\t\t assertThat(response.getText(),containsString(\"Thank you for registration \"));\n\t\t}\n\t\t\n}\n<\/pre>\n<h3><a name=\"mavenbuild\"><\/a>3.3 Maven Build<\/h3>\n<p>I can build my application with command as <code>Run As--&gt;Maven Build--&gt; Provide goals as clean package<\/code>. In case I want to build without running the test cases I can build using the command <code>Run As--&gt;Maven Build--&gt;Provide goals as clean package -Dmaven.test.skip=true<\/code>.<\/p>\n<p><figure id=\"attachment_51580\" aria-describedby=\"caption-attachment-51580\" style=\"width: 840px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/BuildApplication.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51580\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/BuildApplication.jpg\" alt=\"\" width=\"840\" height=\"562\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/BuildApplication.jpg 840w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/BuildApplication-300x201.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/BuildApplication-768x514.jpg 768w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/a><figcaption id=\"caption-attachment-51580\" class=\"wp-caption-text\">Fig.13: Maven Build<\/figcaption><\/figure><\/p>\n<h2><a name=\"Runapplication\"><\/a>4. Run application as spring boot app<\/h2>\n<p>Run the application as below:<\/p>\n<p><figure id=\"attachment_51581\" aria-describedby=\"caption-attachment-51581\" style=\"width: 840px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunSpringBoot.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51581\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunSpringBoot.jpg\" alt=\"\" width=\"840\" height=\"561\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunSpringBoot.jpg 840w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunSpringBoot-300x200.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunSpringBoot-768x513.jpg 768w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/a><figcaption id=\"caption-attachment-51581\" class=\"wp-caption-text\">Fig.14: Spring boot App<\/figcaption><\/figure><\/p>\n<h2><a name=\"projectdemo\"><\/a>5. Project Demo<\/h2>\n<p>Running the code on the browser gives us the following results:<\/p>\n<p><figure id=\"attachment_51582\" aria-describedby=\"caption-attachment-51582\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunonServer.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51582\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunonServer.jpg\" alt=\"\" width=\"600\" height=\"220\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunonServer.jpg 600w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunonServer-300x110.jpg 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-51582\" class=\"wp-caption-text\">Fig.15: Screen1<\/figcaption><\/figure><br \/>\n<figure id=\"attachment_51583\" aria-describedby=\"caption-attachment-51583\" style=\"width: 582px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Secondscreen-.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51583\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Secondscreen-.jpg\" alt=\"\" width=\"582\" height=\"178\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Secondscreen-.jpg 582w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Secondscreen--300x92.jpg 300w\" sizes=\"(max-width: 582px) 100vw, 582px\" \/><\/a><figcaption id=\"caption-attachment-51583\" class=\"wp-caption-text\">Fig.16: Second screen<\/figcaption><\/figure><br \/>\n<figure id=\"attachment_51584\" aria-describedby=\"caption-attachment-51584\" style=\"width: 855px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunTestClass.jpg\"><img decoding=\"async\" class=\"size-full wp-image-51584\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunTestClass.jpg\" alt=\"\" width=\"855\" height=\"434\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunTestClass.jpg 855w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunTestClass-300x152.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunTestClass-768x390.jpg 768w\" sizes=\"(max-width: 855px) 100vw, 855px\" \/><\/a><figcaption id=\"caption-attachment-51584\" class=\"wp-caption-text\">Fig.17: Junit test run<\/figcaption><\/figure><\/p>\n<p>As per the above screenshot my junit tests are successful.<\/p>\n<p>Here I have tested two test cases:<\/p>\n<ol>\n<li>Form is populated with the set default value i.e <code>\"gender\"<\/code>. The dropdown has <code>\"Dont want to say\"<\/code> value, the name text box is blank and <code>countryId<\/code> dropdown is populated with America and India.<\/li>\n<li>In the second test method I have tested the submit functionality of my form whether I am forwarded to my desired Hello page or not.<\/li>\n<\/ol>\n<h2><a name=\"conclusion\"><\/a>6. Conclusion<\/h2>\n<p>That\u2019s all for getting the developers started with the Httpunit. I hope this article served you well. Developers can download the sample application as an Eclipse project in the Downloads section.<\/p>\n<h2><a name=\"download\"><\/a>7. Download the project<\/h2>\n<p>This was an example on how you can use HttpUnit to test your website.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/httpunitsample.7z\"><strong>JUnit HttpUnit Example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello, in this example we shall show you how you can make a use of the JUnit HTTUnit to test web applications. In this example, we will build a small web application and test it using HTTPUnit. This example will show you how you can achieve a browser specific behaviour&nbsp;with HTTPUnit library like sending requests &hellip;<\/p>\n","protected":false},"author":138,"featured_media":6678,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[1680],"class_list":["post-51261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-junit","tag-httpunit"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JUnit HttpUnit Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Hello, in this example we shall show you how you can make a use of the JUnit HTTUnit to test web applications. In this example, we will build a small web\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JUnit HttpUnit Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Hello, in this example we shall show you how you can make a use of the JUnit HTTUnit to test web applications. In this example, we will build a small web\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-11-06T09:00:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-20T11:44:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-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=\"Garima Pandey\" \/>\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=\"Garima Pandey\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/\"},\"author\":{\"name\":\"Garima Pandey\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8600126f509a670ac805468c08cc05a9\"},\"headline\":\"JUnit HttpUnit Example\",\"datePublished\":\"2017-11-06T09:00:35+00:00\",\"dateModified\":\"2019-03-20T11:44:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/\"},\"wordCount\":1184,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"keywords\":[\"httpunit\"],\"articleSection\":[\"junit\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/\",\"name\":\"JUnit HttpUnit Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"datePublished\":\"2017-11-06T09:00:35+00:00\",\"dateModified\":\"2019-03-20T11:44:07+00:00\",\"description\":\"Hello, in this example we shall show you how you can make a use of the JUnit HTTUnit to test web applications. In this example, we will build a small web\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"junit\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/junit\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"JUnit HttpUnit Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8600126f509a670ac805468c08cc05a9\",\"name\":\"Garima Pandey\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Garima-Pandey_avatar_1507665796-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Garima-Pandey_avatar_1507665796-96x96.jpg\",\"caption\":\"Garima Pandey\"},\"description\":\"Garima is a software developer and have more than 7 years of experience in web application development using various java technologies with a passion to write quality code.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/garima-pandey\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JUnit HttpUnit Example - Java Code Geeks","description":"Hello, in this example we shall show you how you can make a use of the JUnit HTTUnit to test web applications. In this example, we will build a small web","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:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/","og_locale":"en_US","og_type":"article","og_title":"JUnit HttpUnit Example - Java Code Geeks","og_description":"Hello, in this example we shall show you how you can make a use of the JUnit HTTUnit to test web applications. In this example, we will build a small web","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-11-06T09:00:35+00:00","article_modified_time":"2019-03-20T11:44:07+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","type":"image\/jpeg"}],"author":"Garima Pandey","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Garima Pandey","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/"},"author":{"name":"Garima Pandey","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8600126f509a670ac805468c08cc05a9"},"headline":"JUnit HttpUnit Example","datePublished":"2017-11-06T09:00:35+00:00","dateModified":"2019-03-20T11:44:07+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/"},"wordCount":1184,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","keywords":["httpunit"],"articleSection":["junit"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/","name":"JUnit HttpUnit Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","datePublished":"2017-11-06T09:00:35+00:00","dateModified":"2019-03-20T11:44:07+00:00","description":"Hello, in this example we shall show you how you can make a use of the JUnit HTTUnit to test web applications. In this example, we will build a small web","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-httpunit-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"junit","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/junit\/"},{"@type":"ListItem","position":5,"name":"JUnit HttpUnit Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8600126f509a670ac805468c08cc05a9","name":"Garima Pandey","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Garima-Pandey_avatar_1507665796-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/Garima-Pandey_avatar_1507665796-96x96.jpg","caption":"Garima Pandey"},"description":"Garima is a software developer and have more than 7 years of experience in web application development using various java technologies with a passion to write quality code.","url":"https:\/\/examples.javacodegeeks.com\/author\/garima-pandey\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/51261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/138"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=51261"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/51261\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/6678"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=51261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=51261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=51261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}