{"id":31893,"date":"2014-11-10T16:00:28","date_gmt":"2014-11-10T14:00:28","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=31893"},"modified":"2023-12-05T16:01:59","modified_gmt":"2023-12-05T14:01:59","slug":"junit-tutorial-unit-testing","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html","title":{"rendered":"JUnit Tutorial for Unit Testing \u2013 The ULTIMATE Guide (PDF Download)"},"content":{"rendered":"<p><strong>EDITORIAL NOTE:<\/strong> <em>We have provided plenty of <a href=\"http:\/\/junit.org\/\">JUnit<\/a> tutorials here at Java Code Geeks, like <a href=\"https:\/\/examples.javacodegeeks.com\/core-java\/junit\/junit-getting-started-example\/\">JUnit Getting Started Example<\/a>, <a href=\"https:\/\/examples.javacodegeeks.com\/core-java\/junit\/junit-using-assertions-and-annotations-example\/\">JUnit Using Assertions and Annotations Example<\/a>, <a href=\"https:\/\/examples.javacodegeeks.com\/core-java\/junit\/junit-annotations-example\/\">JUnit Annotations Example<\/a> and so on.<\/em><\/p>\n<p>However, we prefered to gather all the <a href=\"http:\/\/junit.org\/\">JUnit<\/a> features in one detailed guide for the convenience of the reader. We hope you like it!<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#unit_testing_intro\">1. Unit testing introduction<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#definition\">1.1. What is unit testing?<\/a><\/dt>\n<dt><a href=\"#test_coverage\">1.2. Test coverage<\/a><\/dt>\n<dt><a href=\"#unit_testing_java\">1.3.Unit testing in Java<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#junit_intro\">2. JUnit introduction<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#simple_example\">2.1. JUnit Simple Example using Eclipse<\/a><\/dt>\n<dt><a href=\"#annotations\">2.2. JUnit annotations<\/a><\/dt>\n<dt><a href=\"#assertions\">2.3. JUnit assertions<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#full_example\">3. JUnit complete example using Eclipse<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#initial_steps\">3.1. Initial steps<\/a><\/dt>\n<dt><a href=\"#simple_class\">3.2. Create a java class to be tested<\/a><\/dt>\n<dt><a href=\"#creation_run\">3.3. Create and run a JUnit test case<\/a><\/dt>\n<dt><a href=\"#ignore\">3.4. Using @Ignore annotation<\/a><\/dt>\n<dt><a href=\"#suite_tests\">3.5. Creating suite tests<\/a><\/dt>\n<dt><a href=\"#parameterized\">3.6. Creating parameterized tests<\/a><\/dt>\n<dt><a href=\"#rules\">3.7. Rules<\/a><\/dt>\n<dt><a href=\"#categories\">3.8. Categories<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#command_line\">4. Run JUnit tests from command line<\/a><\/dt>\n<dt><a href=\"#conclusions\">5. Conclusions<\/a><\/dt>\n<\/dl>\n<\/div>\n<p>&nbsp;<\/p>\n<h2><a name=\"unit_testing_intro\"><\/a>1. Unit testing introduction<\/h2>\n<h3><a name=\"definition\"><\/a>1.1. What is unit testing?<\/h3>\n<p>A unit can be a function, a class, a package, or a subsystem. So, the term unit testing refers to the practice of testing such small units of your code, so as to ensure that they work as expected. For example, we can test whether an output is what we expected to see given some inputs or if a condition is true or false.<\/p>\n<p>This practice helps developers to discover failures in their logic behind their code and improve the quality of their code. Also, unit testing can be used so as to ensure that the code will work as expected in case of future changes.<\/p>\n<h3><a name=\"test_coverage\"><\/a>1.2. Test coverage<\/h3>\n<p>In general, the development community has different opinion regarding the percentage of code that should be tested (test coverage). Some developers believe that the code should have 100% test coverage, while others are comprised with a test coverage of 50% or less. In any case, you should write tests for complex or critical parts of your code.<\/p>\n<h3><a name=\"unit_testing_java\"><\/a>1.3. Unit testing in Java<\/h3>\n<p>The most popular testing framework in Java is <a href=\"http:\/\/junit.org\/\">JUnit<\/a>. As this guide is focused to JUnit, more details for this testing framework will presented in the next sections. Another popular testing framework in Java is <a href=\"http:\/\/testng.org\/doc\/index.html\">TestNG<\/a>.<\/p>\n<h2><a name=\"junit_intro\"><\/a>2. JUnit introduction<\/h2>\n<p><a href=\"http:\/\/junit.org\/\">JUnit<\/a> is an open source testing framework which is used to write and run repeatable automated tests, so that we can be ensured that our code works as expected. <a href=\"http:\/\/junit.org\/\">JUnit<\/a> is widely used in industry and can be used as stand alone Java program (from the command line) or within an IDE such as Eclipse.<\/p>\n<p>JUnit provides:<\/p>\n<ul>\n<li>Assertions for testing expected results.<\/li>\n<li>Test features for sharing common test data.<\/li>\n<li>Test suites for easily organizing and running tests.<\/li>\n<li>Graphical and textual test runners.<\/li>\n<\/ul>\n<p>JUnit is used to test:<\/p>\n<ul>\n<li>an entire object<\/li>\n<li>part of an object \u2013 a method or some interacting methods<\/li>\n<li>interaction between several objects<\/li>\n<\/ul>\n<h3><a name=\"simple_example\"><\/a>2.1. JUnit Simple Example using Eclipse<\/h3>\n<p>In this section we will see a simple <a href=\"http:\/\/junit.org\/\">JUnit<\/a> example. First we will present the class we would like to test:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Calculate.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\npublic class Calculate {\n\n\tpublic int sum(int var1, int var2) {\n\t\tSystem.out.println(\"Adding values: \" + var1 + \" + \" + var2);\n\t\treturn var1 + var2;\n\t}\n\n}\n<\/pre>\n<p>In the above source code, we can notice that the class has one public method named <code>sum()<\/code>, which gets as inputs two integers, adds them and returns the result. So, we will test this method. For this purpose, we will create another class including methods that will test each one of the methods of the previous class (in this case, we have only one method to be tested). This is the most common way of usage. Of course, if a method is very complex and extended, we can have more than one test methods for this complex method. The details of creating test cases will be presented in the next sections. Below, there is the code of the class named <code>CalculateTest.java<\/code>, which has the role of our test class:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>CalculateTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport static org.junit.Assert.*;\n\nimport org.junit.Test;\n\npublic class CalculateTest {\n\n\tCalculate calculation = new Calculate();\n\tint sum = calculation.sum(2, 5);\n\tint testSum = 7;\n\n\t@Test\n\tpublic void testSum() {\n\t\tSystem.out.println(\"@Test sum(): \" + sum + \" = \" + testSum);\n\t\tassertEquals(sum, testSum);\n\t}\n\n}\n<\/pre>\n<p>Let&#8217;s explain the above code. Firstly, we can see that there is a <code>@Test<\/code> annotation above the <code>testSum()<\/code> method. This annotation indicates that the public void method to which it is attached can be run as a test case. Hence, the <code>testSum()<\/code> method is the method that will test the <code>sum()<\/code> public method. We can also observe a method called <code>assertEquals(sum, testsum)<\/code>. The method <code>assertEquals ([String message], object expected, object actual)<\/code> takes as inputs two objects and asserts that the two objects are equal.<\/p>\n<p>If we run the test class, by right-clicking in the test class and select <em>Run As -&gt; Junit Test<\/em>, the program output will look like that:<\/p>\n<pre class=\"brush:bash\">Adding values: 2 + 5\n@Test sum(): 7 = 7\n<\/pre>\n<p>To see the actual result of a JUnit test, Eclipse IDE provides a JUnit window which shows the results of the tests. In this case where the test succeeds, the JUnit window does not show any errors or failures, as we can see in the image below:<\/p>\n<p><figure id=\"attachment_32071\" aria-describedby=\"caption-attachment-32071\" style=\"width: 521px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/everythingOKwater.png\"><img decoding=\"async\" class=\"size-full wp-image-32071\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/everythingOKwater.png\" alt=\"Figure 1\" width=\"521\" height=\"444\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/everythingOKwater.png 521w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/everythingOKwater-300x255.png 300w\" sizes=\"(max-width: 521px) 100vw, 521px\" \/><\/a><figcaption id=\"caption-attachment-32071\" class=\"wp-caption-text\">Figure 1: JUnit window after a successful test.<\/figcaption><\/figure><\/p>\n<p>Now, if we change this line of code:<\/p>\n<pre class=\"brush:java\">int testSum = 10;\n<\/pre>\n<p>so that the integers to be tested are not equal, the output will be:<\/p>\n<pre class=\"brush:bash\">Adding values: 2 + 5\n@Test sum(): 7 = 10\n<\/pre>\n<p>And in the JUnit window, an error will appear and this message will be displayed:<\/p>\n<pre class=\"brush:bash\">java.lang.AssertionError: expected: but was:\nat com.javacodegeeks.junit.CalculateTest.testSum(CalculateTest.java:16)<\/pre>\n<h3><a name=\"annotations\"><\/a>2.2. JUnit annotations<\/h3>\n<p>In this section we will mention the basic annotations supported in Junit 4. The table below presents a summary of those annotations:<\/p>\n<table border=\"2\">\n<tbody>\n<tr>\n<th style=\"width: 250px; background-color: #dedede;\"><strong>Annotation<\/strong><\/th>\n<th style=\"background-color: #dedede;\"><strong>Description<\/strong><\/th>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code><strong> @Test<\/strong><br \/>\npublic void method() <\/code><\/td>\n<td>The <code>Test<\/code> annotation indicates that the public void method to which it is attached can be run as a test case.<\/td>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code><strong> @Before<\/strong><br \/>\npublic void method() <\/code><\/td>\n<td>The <code>Before<\/code> annotation indicates that this method must be executed before each test in the class, so as to execute some preconditions necessary for the test.<\/td>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code><strong> @BeforeClass<\/strong><br \/>\npublic static void method() <\/code><\/td>\n<td>The <code>BeforeClass<\/code> annotation indicates that the static method to which is attached must be executed once and before all tests in the class. That happens when the test methods share computationally expensive setup (e.g. connect to database).<\/td>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code><strong> @After<\/strong><br \/>\npublic void method() <\/code><\/td>\n<td>The <code>After<\/code> annotation indicates that this method gets executed after execution of each test (e.g. reset some variables after execution of every test, delete temporary variables etc)<\/td>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code><strong> @AfterClass<\/strong><br \/>\npublic static void method() <\/code><\/td>\n<td>The <code>AfterClass<\/code> annotation can be used when a method needs to be executed after executing all the tests in a JUnit Test Case class so as to clean-up the expensive set-up (e.g disconnect from a database). Attention: The method attached with this annotation (similar to <code>BeforeClass<\/code>) must be defined as static.<\/td>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code><strong> @Ignore<\/strong><br \/>\npublic static void method() <\/code><\/td>\n<td>The <code>Ignore<\/code> annotation can be used when you want temporarily disable the execution of a specific test. Every method that is annotated with <code>@Ignore<\/code> won&#8217;t be executed.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Let&#8217;s see an example of a test class with some of the annotations mentioned above.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>AnnotationsTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport static org.junit.Assert.*;\nimport java.util.*;\nimport org.junit.*;\n\npublic class AnnotationsTest {\n\n\tprivate ArrayList testList;\n\n\t@BeforeClass\n\tpublic static void onceExecutedBeforeAll() {\n\t\tSystem.out.println(\"@BeforeClass: onceExecutedBeforeAll\");\n\t}\n\n\t@Before\n\tpublic void executedBeforeEach() {\n\t\ttestList = new ArrayList();\n\t\tSystem.out.println(\"@Before: executedBeforeEach\");\n\t}\n\n\t@AfterClass\n\tpublic static void onceExecutedAfterAll() {\n\t\tSystem.out.println(\"@AfterClass: onceExecutedAfterAll\");\n\t}\n\n\t@After\n\tpublic void executedAfterEach() {\n\t\ttestList.clear();\n\t\tSystem.out.println(\"@After: executedAfterEach\");\n\t}\n\n\t@Test\n\tpublic void EmptyCollection() {\n\t\tassertTrue(testList.isEmpty());\n\t\tSystem.out.println(\"@Test: EmptyArrayList\");\n\n\t}\n\n\t@Test\n\tpublic void OneItemCollection() {\n\t\ttestList.add(\"oneItem\");\n\t\tassertEquals(1, testList.size());\n\t\tSystem.out.println(\"@Test: OneItemArrayList\");\n\t}\n\n\t@Ignore\n\tpublic void executionIgnored() {\n\n\t\tSystem.out.println(\"@Ignore: This execution is ignored\");\n\t}\n}\n<\/pre>\n<p>If we run the above test, the console output would be the following:<\/p>\n<pre class=\"brush:bash\">@BeforeClass: onceExecutedBeforeAll\n@Before: executedBeforeEach\n@Test: EmptyArrayList\n@After: executedAfterEach\n@Before: executedBeforeEach\n@Test: OneItemArrayList\n@After: executedAfterEach\n@AfterClass: onceExecutedAfterAll\n<\/pre>\n<h3><a name=\"assertions\"><\/a>2.3. JUnit assertions<\/h3>\n<p>In this section we will present a number of assertion methods. All those methods are provided by the <code>Assert<\/code> class which extends the <code>class java.lang.Object<\/code> and they are useful for writing tests so as to detect failures. In the table below there is a more detailed explanation of the most commonly used assertion methods.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<table border=\"2\">\n<tbody>\n<tr>\n<th style=\"background-color: #dedede;\"><strong>Assertion<\/strong><\/th>\n<th style=\"background-color: #dedede;\"><strong>Description<\/strong><\/th>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code>void assertEquals([String message], expected value, actual value)<\/code><\/td>\n<td>Asserts that two values are equal. Values might be type of int, short, long, byte, char or java.lang.Object. The first argument is an optional String message.<\/td>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code>void assertTrue([String message], boolean condition)<\/code><\/td>\n<td>Asserts that a condition is true.<\/td>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code>void assertFalse([String message],boolean condition)<\/code><\/td>\n<td>Asserts that a condition is false.<\/td>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code>void assertNotNull([String message], java.lang.Object object)<\/code><\/td>\n<td>Asserts that an object is not null.<\/td>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code>void assertNull([String message], java.lang.Object object)<\/code><\/td>\n<td>Asserts that an object is null.<\/td>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code>void assertSame([String message], java.lang.Object expected, java.lang.Object actual)<\/code><\/td>\n<td>Asserts that the two objects refer to the same object.<\/td>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code>void assertNotSame([String message], java.lang.Object unexpected, java.lang.Object actual)<\/code><\/td>\n<td>Asserts that the two objects do not refer to the same object.<\/td>\n<\/tr>\n<tr style=\"height: 70px;\">\n<td><code>void assertArrayEquals([String message], expectedArray, resultArray)<\/code><\/td>\n<td>Asserts that the array expected and the resulted array are equal. The type of Array might be int, long, short, char, byte or java.lang.Object.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Let&#8217;s see an example of some of the aforementioned assertions.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>AssertionsTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport static org.junit.Assert.*;\nimport org.junit.Test;\n\npublic class AssertionsTest {\n\n\t@Test\n\tpublic void test() {\n\t\tString obj1 = \"junit\";\n\t\tString obj2 = \"junit\";\n\t\tString obj3 = \"test\";\n\t\tString obj4 = \"test\";\n\t\tString obj5 = null;\n\t\tint var1 = 1;\n\t\tint var2 = 2;\n\t\tint[] arithmetic1 = { 1, 2, 3 };\n\t\tint[] arithmetic2 = { 1, 2, 3 };\n\n\t\tassertEquals(obj1, obj2);\n\n\t\tassertSame(obj3, obj4);\n\n\t\tassertNotSame(obj2, obj4);\n\n\t\tassertNotNull(obj1);\n\n\t\tassertNull(obj5);\n\n\t\tassertTrue(var1  var2);\n\n\t\tassertArrayEquals(arithmetic1, arithmetic2);\n\t}\n\n}\n<\/pre>\n<p>In the class above we can see how these assert methods work.<\/p>\n<ul>\n<li>The <code>assertEquals()<\/code> method will return normally if the two compared objects are equal, otherwise a failure will be displayed in the JUnit window and the test will abort.<\/li>\n<li>The <code>assertSame()<\/code> and <code>assertNotSame()<\/code> methods tests if two object references point to exactly the same object.<\/li>\n<li>The <code>assertNull()<\/code> and <code>assertNotNull()<\/code> methods test whether a variable is null or not null.<\/li>\n<li>The <code>assertTrue()<\/code> and <code>assertFalse()<\/code> methods tests if a condition or a variable is true or false.<\/li>\n<li>The <code>assertArrayEquals()<\/code> will compare the two arrays and if they are equal, the method will proceed without errors. Otherwise, a failure will be displayed in the JUnit window and the test will abort.<\/li>\n<\/ul>\n<h2><a name=\"full_example\"><\/a>3. JUnit complete example using Eclipse<\/h2>\n<p>In this section we will show a complete example of using JUnit. We will see in detail how to create and run tests and we will show how to use specific annotations and assertions of JUnit.<\/p>\n<h3><a name=\"initial_steps\"><\/a>3.1. Initial Steps<\/h3>\n<p>Let&#8217;s create a java project named <em>JUnitGuide<\/em>. In the <em>src<\/em> folder, we right-click and select <em>New -&gt; Package<\/em>, so as to create a new package named <code>com.javacodegeeks.junit<\/code> where we will locate the class to be tested. For the test classes, it is considered as good practice to create a new source folder dedicated to tests, so that the classes to be tested and the test classes will be in different source folders. For this purpose, right-click your project, select <em>New -&gt; Source Folder<\/em>, name the new source folder test and click <em>Finish<\/em>.<\/p>\n<p><figure id=\"attachment_31948\" aria-describedby=\"caption-attachment-31948\" style=\"width: 528px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/waterjunitGuide_testFolder1.png\"><img decoding=\"async\" class=\"size-full wp-image-31948\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/waterjunitGuide_testFolder1.png\" alt=\"Create a new source folder named test.\" width=\"528\" height=\"503\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/waterjunitGuide_testFolder1.png 528w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/waterjunitGuide_testFolder1-300x285.png 300w\" sizes=\"(max-width: 528px) 100vw, 528px\" \/><\/a><figcaption id=\"caption-attachment-31948\" class=\"wp-caption-text\">Figure 2: Create a new source folder named <em>test<\/em>.<\/figcaption><\/figure><\/p>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nAlternatively, you can create a new source folder by right-clicking your project and select <em>Properties -&gt; Java Build Path<\/em>, select the tab <em>Source<\/em>, select <em>Add Folder -&gt; Create New Folder<\/em>, write the name <em>test<\/em> and press <em>Finish<\/em>.<\/div>\n<p>You can easily see that there are two source folders in your project:<\/p>\n<p><figure id=\"attachment_31949\" aria-describedby=\"caption-attachment-31949\" style=\"width: 730px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/waterJunit_guide_test_folder2.png\"><img decoding=\"async\" class=\"size-full wp-image-31949\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/waterJunit_guide_test_folder2.png\" alt=\"Figure 2\" width=\"730\" height=\"556\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/waterJunit_guide_test_folder2.png 730w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/waterJunit_guide_test_folder2-300x228.png 300w\" sizes=\"(max-width: 730px) 100vw, 730px\" \/><\/a><figcaption id=\"caption-attachment-31949\" class=\"wp-caption-text\">Figure 3<\/figcaption><\/figure><\/p>\n<p>You can also create a new package in the newly created test folder, which will be called <code>com.javacodegeeks.junit<\/code>, so that your test classes won&#8217;t be located to the default package and we are ready to start!<\/p>\n<h3><a name=\"simple_class\"><\/a>3.2. Create the java class to be tested<\/h3>\n<p>Right-click the <em>src<\/em> folder and create a new java class called <code>FirstDayAtSchool.java<\/code>. This will be the class whose public methods will be tested.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>FirstDayAtSchool.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport java.util.Arrays;\n\npublic class FirstDayAtSchool {\n\n\tpublic String[] prepareMyBag() {\n\t\tString[] schoolbag = { \"Books\", \"Notebooks\", \"Pens\" };\n\t\tSystem.out.println(\"My school bag contains: \"\n\t\t\t\t+ Arrays.toString(schoolbag));\n\t\treturn schoolbag;\n\t}\n\n\tpublic String[] addPencils() {\n\t\tString[] schoolbag = { \"Books\", \"Notebooks\", \"Pens\", \"Pencils\" };\n\t\tSystem.out.println(\"Now my school bag contains: \"\n\t\t\t\t+ Arrays.toString(schoolbag));\n\t\treturn schoolbag;\n\t}\n}\n<\/pre>\n<h3><a name=\"creation_run\"><\/a>3.3. Create and run a JUnit test case<\/h3>\n<p>To create a JUnit test case for the existing class <code>FirstDayAtSchool.java<\/code>, right-click on it in the Package Explorer view and select <em>New \u2192 JUnit Test Case<\/em>. Change the source folder so that the class will be located to <em>test<\/em> source folder and ensure that the flag <em>New JUnit4 test<\/em> is selected.<\/p>\n<p><figure id=\"attachment_31955\" aria-describedby=\"caption-attachment-31955\" style=\"width: 527px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_new_test.png\"><img decoding=\"async\" class=\"size-full wp-image-31955\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_new_test.png\" alt=\"Create a new test class.\" width=\"527\" height=\"605\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_new_test.png 527w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_new_test-261x300.png 261w\" sizes=\"(max-width: 527px) 100vw, 527px\" \/><\/a><figcaption id=\"caption-attachment-31955\" class=\"wp-caption-text\">Figure 4: Create a new test class.<\/figcaption><\/figure><\/p>\n<p>Then, click <em>Finish<\/em>. If your project does not contain the JUnit library in its classpath, the following message will be displayed so as to add the JUnit library to the classpath:<\/p>\n<p><figure id=\"attachment_31953\" aria-describedby=\"caption-attachment-31953\" style=\"width: 527px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_new_test1.png\"><img decoding=\"async\" class=\"size-full wp-image-31953\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_new_test1.png\" alt=\"Add JUnit4 library to your project's build path.\" width=\"527\" height=\"605\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_new_test1.png 527w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_new_test1-261x300.png 261w\" sizes=\"(max-width: 527px) 100vw, 527px\" \/><\/a><figcaption id=\"caption-attachment-31953\" class=\"wp-caption-text\">Figure 5: Add JUnit4 library to your project&#8217;s build path.<\/figcaption><\/figure><\/p>\n<p>Below, there is the code of the class named <code>FirstDayAtSchoolTest.java<\/code>, which is our test class:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>FirstDayAtSchool.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport static org.junit.Assert.*;\n\nimport org.junit.Test;\n\npublic class FirstDayAtSchoolTest {\n\n\tFirstDayAtSchool school = new FirstDayAtSchool();\n\tString[] bag1 = { \"Books\", \"Notebooks\", \"Pens\" };\n\tString[] bag2 = { \"Books\", \"Notebooks\", \"Pens\", \"Pencils\" };\n\n\t@Test\n\tpublic void testPrepareMyBag() {\n\t\tSystem.out.println(\"Inside testPrepareMyBag()\");\n\t\tassertArrayEquals(bag1, school.prepareMyBag());\n\t}\n\n\t@Test\n\tpublic void testAddPencils() {\n\t\tSystem.out.println(\"Inside testAddPencils()\");\n\t\tassertArrayEquals(bag2, school.addPencils());\n\t}\n\n}\n<\/pre>\n<p>Now we can run the test case by right-clicking on the test class and select <em>Run As -&gt; JUnit Test<\/em>.<\/p>\n<p>The program output will look like that:<\/p>\n<pre class=\"brush:bash\">Inside testPrepareMyBag()\nMy school bag contains: [Books, Notebooks, Pens]\nInside testAddPencils()\nNow my school bag contains: [Books, Notebooks, Pens, Pencils]\n<\/pre>\n<p>and in the JUnit view will be no failures or erros. If we change one of the arrays, so that it contains more than the expected elements:<\/p>\n<pre class=\"brush:java\">String[] bag2 = { \"Books\", \"Notebooks\", \"Pens\", \"Pencils\", \"Rulers\"};\n<\/pre>\n<p>and we run again the test class, the JUnit view will contain a failure:<\/p>\n<p><figure id=\"attachment_31957\" aria-describedby=\"caption-attachment-31957\" style=\"width: 546px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_failure1.png\"><img decoding=\"async\" class=\"size-full wp-image-31957\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_failure1.png\" alt=\"Test failure\" width=\"546\" height=\"474\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_failure1.png 546w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_failure1-300x260.png 300w\" sizes=\"(max-width: 546px) 100vw, 546px\" \/><\/a><figcaption id=\"caption-attachment-31957\" class=\"wp-caption-text\">Figure 6: Test failure<\/figcaption><\/figure><\/p>\n<p>Else, if we change again one of the arrays, so that it contains a different element than the expected:<\/p>\n<pre class=\"brush:java\">String[] bag1 = { \"Books\", \"Notebooks\", \"Rulers\" };\n<\/pre>\n<p>and we run again the test class, the JUnit view will contain once again a failure:<\/p>\n<p><figure id=\"attachment_31958\" aria-describedby=\"caption-attachment-31958\" style=\"width: 585px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_failure2.png\"><img decoding=\"async\" class=\"size-full wp-image-31958\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_failure2.png\" alt=\"Test failure\" width=\"585\" height=\"499\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_failure2.png 585w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_failure2-300x255.png 300w\" sizes=\"(max-width: 585px) 100vw, 585px\" \/><\/a><figcaption id=\"caption-attachment-31958\" class=\"wp-caption-text\">Figure 7: Test failure<\/figcaption><\/figure><\/p>\n<h3><a name=\"ignore\"><\/a>3.4. Using <code>@Ignore<\/code> annotation<\/h3>\n<p>Let&#8217;s see in the above example how can we use the <code>@Ignore<\/code> annotation. In the test class <code>FirstDayAtSchoolTest<\/code> we will add the <code>@Ignore<\/code> annotation to the <code>testAddPencils()<\/code> method. In that way, we expect that this testing method will be ignored and won&#8217;t be executed.<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport static org.junit.Assert.*;\n\nimport org.junit.Ignore;\nimport org.junit.Test;\n\npublic class FirstDayAtSchoolTest {\n\n\tFirstDayAtSchool school = new FirstDayAtSchool();\n\tString[] bag1 = { \"Books\", \"Notebooks\", \"Pens\" };\n\tString[] bag2 = { \"Books\", \"Notebooks\", \"Pens\", \"Pencils\" };\n\n\t@Test\n\tpublic void testPrepareMyBag() {\n\t\tSystem.out.println(\"Inside testPrepareMyBag()\");\n\t\tassertArrayEquals(bag1, school.prepareMyBag());\n\t}\n\n\t@Ignore\n\t@Test\n\tpublic void testAddPencils() {\n\t\tSystem.out.println(\"Inside testAddPencils()\");\n\t\tassertArrayEquals(bag2, school.addPencils());\n\t}\n\n}\n<\/pre>\n<p>Indeed, this is what happens according to the output:<\/p>\n<pre class=\"brush:bash\">Inside testPrepareMyBag()\nMy school bag contains: [Books, Notebooks, Pens]\n<\/pre>\n<p>Now, we will remove the <code>@Ignore<\/code> annotation from the <code>testAddPencils()<\/code> method and we will annotate the whole class instead.<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport static org.junit.Assert.*;\n\nimport org.junit.Ignore;\nimport org.junit.Test;\n\n@Ignore\npublic class FirstDayAtSchoolTest {\n\n\tFirstDayAtSchool school = new FirstDayAtSchool();\n\tString[] bag1 = { \"Books\", \"Notebooks\", \"Pens\" };\n\tString[] bag2 = { \"Books\", \"Notebooks\", \"Pens\", \"Pencils\" };\n\n\t@Test\n\tpublic void testPrepareMyBag() {\n\t\tSystem.out.println(\"Inside testPrepareMyBag()\");\n\t\tassertArrayEquals(bag1, school.prepareMyBag());\n\t}\n\n\t\n\t@Test\n\tpublic void testAddPencils() {\n\t\tSystem.out.println(\"Inside testAddPencils()\");\n\t\tassertArrayEquals(bag2, school.addPencils());\n\t}\n\n}\n<\/pre>\n<p>The whose test class won&#8217;t be executed, so no result will be displayed int the console output and in the junit view:<\/p>\n<p><figure id=\"attachment_31959\" aria-describedby=\"caption-attachment-31959\" style=\"width: 468px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_ignore.png\"><img decoding=\"async\" class=\"size-full wp-image-31959\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_ignore.png\" alt=\"Ignore annotation\" width=\"468\" height=\"226\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_ignore.png 468w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/water_ignore-300x144.png 300w\" sizes=\"(max-width: 468px) 100vw, 468px\" \/><\/a><figcaption id=\"caption-attachment-31959\" class=\"wp-caption-text\">Figure 8<\/figcaption><\/figure><\/p>\n<h3><a name=\"suite_tests\"><\/a>3.5. Creating suite tests<\/h3>\n<p>In this section, we will see how to create suite tests. A test suite is a collection of some test cases from different classes that can be run all together using <code>@RunWith<\/code> and <code>@Suite<\/code> annotations. This is very helpful if you have many test classes and you want to run them all together instead of running each test one at a time.<\/p>\n<p>When a class is annotated with <code>@RunWith<\/code>, JUnit will invoke the class in which is annotated so as to run the tests, instead of using the runner built into JUnit.<\/p>\n<p>Based on the classes of the previous sections, we can create two test classes. The one class will test the public method <code>prepareMyBag()<\/code> and the other test class will test the method <code>addPencils()<\/code>. Hence, we will eventually have the classes below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>PrepareMyBagTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport org.junit.Test;\nimport static org.junit.Assert.*;\n\npublic class PrepareMyBagTest {\n\n\tFirstDayAtSchool school = new FirstDayAtSchool();\n\n\tString[] bag = { \"Books\", \"Notebooks\", \"Pens\" };\n\n\t@Test\n\tpublic void testPrepareMyBag() {\n\n\t\tSystem.out.println(\"Inside testPrepareMyBag()\");\n\t\tassertArrayEquals(bag, school.prepareMyBag());\n\n\t}\n\n}\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>AddPencilsTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport org.junit.Test;\nimport static org.junit.Assert.*;\n\npublic class AddPencilsTest {\n\n\tFirstDayAtSchool school = new FirstDayAtSchool();\n\n\tString[] bag = { \"Books\", \"Notebooks\", \"Pens\", \"Pencils\" };\n\n\t@Test\n\tpublic void testAddPencils() {\n\n\t\tSystem.out.println(\"Inside testAddPencils()\");\n\t\tassertArrayEquals(bag, school.addPencils());\n\n\t}\n\n}\n<\/pre>\n<p>Now we will create a test suite so as to run the above classes together. Right-click the <em>test<\/em> source folder and create a new java class named <code>SuiteTest.java<\/code> with the following code:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SuiteTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport org.junit.runner.RunWith;\nimport org.junit.runners.Suite;\n\n@RunWith(Suite.class)\n@Suite.SuiteClasses({ PrepareMyBagTest.class, AddPencilsTest.class })\npublic class SuitTest {\n\n}\n<\/pre>\n<p>With the <code>@Suite.SuiteClasses<\/code> annotation you can define which test classes will be included in the execution.<\/p>\n<p>So, if you right-click the test suite and select <em>Run As -&gt; JUnit Test<\/em>, the execution of both test classes will take place with the order that has been defined in the <code>@Suite.SuiteClasses<\/code> annotation.<br \/>\n[ulp id=&#8217;W7z6P4JKWhqanUyq&#8217;]<br \/>\n&nbsp;<\/p>\n<h3><a name=\"parameterized\"><\/a>3.6. Creating parameterized tests<\/h3>\n<p>In this section we will see how to create parameterized tests. For this purpose, we will use the class mentioned in section 2.1 which provides a public method for adding integers. So, this will be the class to be tested.<\/p>\n<p>But when a test class can be considered as a parameterized test class? Of course, when it fullfills all the following requirements:<\/p>\n<ul>\n<li>The class is annotated with <code>@RunWith(Parameterized.class)<\/code>.<br \/>\nAs explained in the previous section, <code>@RunWith<\/code> annotation enables JUnit to invoke the class in which is annotated to run the tests, instead of using the runner built into JUnit. <code>Parameterized<\/code> is a runner inside JUnit that will run the same test case with different set of inputs.<\/li>\n<li>The class has a single constructor that stores the test data.<\/li>\n<li>The class has a static method that generates and returns test data and is annotated with the <code>@Parameters<\/code> annotation.<\/li>\n<li>The class has a test, which obviously means that it needs a method annotated with the <code>@Test<\/code> annotation.<\/li>\n<\/ul>\n<p>Now, we will create a new test class named <code>CalculateTest.java<\/code>, which will follow the guidelines mentioned above. The source code of this class follows.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>CalculateTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport static org.junit.Assert.assertEquals;\nimport java.util.Arrays;\nimport java.util.Collection;\n\nimport org.junit.Test;\nimport org.junit.runner.RunWith;\nimport org.junit.runners.Parameterized;\nimport org.junit.runners.Parameterized.Parameters;\n\n@RunWith(Parameterized.class)\npublic class CalculateTest {\n\n\tprivate int expected;\n\tprivate int first;\n\tprivate int second;\n\n\tpublic CalculateTest(int expectedResult, int firstNumber, int secondNumber) {\n\t\tthis.expected = expectedResult;\n\t\tthis.first = firstNumber;\n\t\tthis.second = secondNumber;\n\t}\n\n\t@Parameters\n\tpublic static Collection addedNumbers() {\n\t\treturn Arrays.asList(new Integer[][] { { 3, 1, 2 }, { 5, 2, 3 },\n\t\t\t\t{ 7, 3, 4 }, { 9, 4, 5 }, });\n\t}\n\n\t@Test\n\tpublic void sum() {\n\t\tCalculate add = new Calculate();\n\t\tSystem.out.println(\"Addition with parameters : \" + first + \" and \"\n\t\t\t\t+ second);\n\t\tassertEquals(expected, add.sum(first, second));\n\t}\n}\n<\/pre>\n<p>As we can observe in the class above, it fullfills all the above requirements. The method <code>addedNumbers<\/code> annotated with <code>@Parameters<\/code> returns a Collection of Arrays. Each array includes the inputs\/output numbers of each test execution. The number of elements in each array must be the same with the number of parameters in the constructor. So, in this specific case, each array includes three elements, two elements that represent the numbers to be added and one element for the result.<\/p>\n<p>If we run the <code>CalculateTest<\/code> test case, the console output will be the following:<\/p>\n<pre class=\"brush:bash\">Addition with parameters : 1 and 2\nAdding values: 1 + 2\nAddition with parameters : 2 and 3\nAdding values: 2 + 3\nAddition with parameters : 3 and 4\nAdding values: 3 + 4\nAddition with parameters : 4 and 5\nAdding values: 4 + 5\n<\/pre>\n<p>As we see in the output, the test case is executed four times, which is the number of inputs in the method annotated with <code>@Parameters<\/code> annotation.<\/p>\n<h3><a name=\"rules\"><\/a>3.7. Rules<\/h3>\n<p>In this section we present a new feature of JUnit called <em>Rules<\/em> which allows very flexible addition or redefinition of the behavior of each test method in a test class. For this purpose, <code>@Rule<\/code> annotation should be used so as to mark public fields of a test class. Those fields should be of type <a href=\"http:\/\/junit.org\/apidocs\/org\/junit\/rules\/MethodRule.html\"><code>MethodRule<\/code><\/a>, which is an alteration in how a test method is run and reported. Multiple <a href=\"http:\/\/junit.org\/apidocs\/org\/junit\/rules\/MethodRule.html\"><code>MethodRules<\/code><\/a> can be applied to a test method. <a href=\"http:\/\/junit.org\/apidocs\/org\/junit\/rules\/MethodRule.html\"><code>MethodRule<\/code><\/a> interface has a lot of implementations, such as <a href=\"http:\/\/junit.org\/apidocs\/org\/junit\/rules\/ErrorCollector.html\"><code>ErrorCollector<\/code><\/a> which allows execution of a test to continue after the first problem is found, <a href=\"http:\/\/junit.org\/apidocs\/org\/junit\/rules\/ExpectedException.html\"><code>ExpectedException<\/code><\/a> which allows in-test specification of expected exception types and messages, <a href=\"http:\/\/junit.org\/apidocs\/org\/junit\/rules\/TestName.html\"><code>TestName<\/code><\/a> which makes the current test name available inside test methods, and many others. Except for those already defined rules, developers can create their own custom rules and use them in their test cases as they wish.<\/p>\n<p>Below we present the way we can use one of the existing rules named <a href=\"http:\/\/junit.org\/apidocs\/org\/junit\/rules\/TestName.html\"><code>TestName<\/code><\/a> in our own tests. <a href=\"http:\/\/junit.org\/apidocs\/org\/junit\/rules\/TestName.html\"><code>TestName<\/code><\/a> is invoked when a test is about to start.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>NameRuleTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport static org.junit.Assert.*;\n\nimport org.junit.*;\nimport org.junit.rules.TestName;\n\npublic class NameRuleTest {\n\t@Rule\n\tpublic TestName name = new TestName();\n\n\t@Test\n\tpublic void testA() {\n\t\tSystem.out.println(name.getMethodName());\n\t\tassertEquals(\"testA\", name.getMethodName());\n\n\t}\n\n\t@Test\n\tpublic void testB() {\n\t\tSystem.out.println(name.getMethodName());\n\t\tassertEquals(\"testB\", name.getMethodName());\n\t}\n}\n<\/pre>\n<p>We can see that the <code>@Rule<\/code> annotation marks the public field <code>name<\/code> which is of type <code>MethodRule<\/code> and specifically, <code>TestName<\/code> type. Then, we can use in our tests this <code>name<\/code> field and find for example the name of the test method, in this specific case.<\/p>\n<h3><a name=\"categories\"><\/a>3.8. Categories<\/h3>\n<p>Another new feature of JUnit is called <em>Categories<\/em> and allows you to group certain kinds of tests together and even include or exclude groups (categories). For example, you can separate slow tests from fast tests. To assign a test case or a method to one of those categories the <code>@Category<\/code> annotation is provided. Below there is an example of how we can use this nice feature of JUnit, based on the release notes of <a href=\"https:\/\/github.com\/junit-team\/junit\/blob\/master\/doc\/ReleaseNotes4.8.md\">JUnit 4.8.<\/a><\/p>\n<pre class=\"brush:java\">public interface FastTests { \/* category marker *\/\n}<\/pre>\n<pre class=\"brush:java\">public interface SlowTests { \/* category marker *\/\n}<\/pre>\n<p>Firstly, we define two categories, FastTests and SlowTests. A category can be either a class or an interface.<\/p>\n<pre class=\"brush:java\">public class A {\n  @Test\n  public void a() {\n    fail();\n  }\n\n  @Category(SlowTests.class)\n  @Test\n  public void b() {\n  }\n}\n<\/pre>\n<p>In the above code, we mark the test method <code>b()<\/code> of class <code>A<\/code> with <code>@Category<\/code> annotation so as to indicate that this specific method belongs to category <code>SlowTests<\/code>. So, we are able to mark not only whole classes but also some of their test methods individually.<\/p>\n<pre class=\"brush:java\">@Category({ SlowTests.class, FastTests.class })\npublic class B {\n  @Test\n  public void c() {\n  }\n}\n<\/pre>\n<p>In the above sample of code, we can see that the whole class <code>B<\/code> is annotated with <code>@Category<\/code> annotation . Annotating a test class with <code>@Category<\/code> annotation automatically includes all its test methods in this category. We can also see that a test class or a test method can belong to more than one categories.<\/p>\n<pre class=\"brush:java\">@RunWith(Categories.class)\n@IncludeCategory(SlowTests.class)\n@SuiteClasses({ A.class, B.class })\n\/\/ Note that Categories is a kind of Suite\npublic class SlowTestSuite {\n  \/\/ Will run A.b and B.c, but not A.a\n}<\/pre>\n<p>In this sample of code, we notice that there is a suite test named <code>SlowTestSuite<\/code>. Basically, categories are a kind of suite. In this suite, we observe a new annotation called <code>@IncludeCategory<\/code>, indicating which categories will be included in the execution. In this specific case, methods belonging to SlowTests category will be executed. Hence, only the test method <code>b()<\/code> of class <code>A<\/code> will be executed as well as the test method <code>c()<\/code> of class <code>B<\/code>, which both belong to SlowTests category.<\/p>\n<pre class=\"brush:java\">@RunWith(Categories.class)\n@IncludeCategory(SlowTests.class)\n@ExcludeCategory(FastTests.class)\n@SuiteClasses({ A.class, B.class })\n\/\/ Note that Categories is a kind of Suite\npublic class SlowTestSuite {\n  \/\/ Will run A.b, but not A.a or B.c\n} \n<\/pre>\n<p>Finally, we change a little bit the test suite and we add one more new annotation called <code>@ExcludeCategory<\/code>, indicating which categories will be excluded from the execution. In this specific case, only the test method <code>b()<\/code> of class <code>A<\/code> will be executed, as this is the only test method that belongs explicitly to SlowTests category.<\/p>\n<p>We notice that in both cases, the test method <code>a()<\/code> of class <code>A<\/code> won&#8217;t be executed as it doesn&#8217;t belong to any category.<\/p>\n<h2><a name=\"command_line\"><\/a>4. Run JUnit tests from command line<\/h2>\n<p>You can run your JUnit test outside Eclipse, by using the <code>org.junit.runner.JUnitCore<\/code> class. This class provides the <code>runClasses()<\/code> method which allows you to execute one or several test classes. The return type of <code>runClasses()<\/code> method is an object of the type <code>org.junit.runner.Result<\/code>. This object can be used to collect information about the tests. Also, in case there is a failed test, you can use the object <code>org.junit.runner.notification.Failure<\/code> which holds description of the failed tests.<\/p>\n<p>The procedure below shows how to run your test outside Eclipse.<\/p>\n<p>Create a new Java class named <code>JunitRunner.java<\/code> with the following code:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>JunitRunner.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.junit;\n\nimport org.junit.runner.JUnitCore;\nimport org.junit.runner.Result;\nimport org.junit.runner.notification.Failure;\n\npublic class JunitRunner {\n\n\tpublic static void main(String[] args) {\n\n\t\tResult result = JUnitCore.runClasses(AssertionsTest.class);\n\t\tfor (Failure fail : result.getFailures()) {\n\t\t\tSystem.out.println(fail.toString());\n\t\t}\n\t\tif (result.wasSuccessful()) {\n\t\t\tSystem.out.println(\"All tests finished successfully...\");\n\t\t}\n\t}\n}\n<\/pre>\n<p>As an example, we choose to run the <code>AssertionsTest<\/code> test class.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>Open command prompt and move down directories so as to find the directory where the two classes are located.<\/li>\n<li>Compile the Test class and the Runner class.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre class=\"brush:bash\">C:\\Users\\konstantina\\eclipse_luna_workspace\\JUnitGuide\\test\\com\\javacodegeeks\\junit&gt;javac -classpath \"C:\\Users\\konstantina\\Downloads\\junit-4.11.jar\";\"C:\\Users\\konstantina\\Downloads\\hamcrest-core-1.3.jar\"; AssertionsTest.java JunitRunner.java<\/pre>\n<p><em>As we did in Eclipse, we should also include <a href=\"https:\/\/github.com\/junit-team\/junit\/wiki\/Download-and-Install#plain-old-jar\">library jars<\/a> of JUnit to our classpath.<\/em><\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>Now run the <code>JunitRunner<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre class=\"brush:bash\">C:\\Users\\konstantina\\eclipse_luna_workspace\\JUnitGuide\\test\\com\\javacodegeeks\\junit&gt;java -classpath \"C:\\Users\\konstantina\\Downloads\\junit-4.11.jar\";\"C:\\Users\\konstantina\\Downloads\\hamcrest-core-1.3.jar\"; JunitRunner<\/pre>\n<p>Here is the output:<\/p>\n<pre class=\"brush:bash\">All tests finished successfully... \n<\/pre>\n<h2><a name=\"conclusions\"><\/a>5. Conclusions<\/h2>\n<p>This was a detailed guide about <a href=\"http:\/\/junit.org\/\">JUnit<\/a> testing framework, the most popular testing framework in Java.<\/p>\n<p>If you enjoyed this, then <a href=\"http:\/\/javacodegeeks.us4.list-manage.com\/subscribe?u=09cef08fc376e6da2dace7d09&amp;id=cc9180703b\">subscribe to our newsletter<\/a> to enjoy weekly updates and complimentary whitepapers! Also, check out <a href=\"https:\/\/academy.javacodegeeks.com\/\">JCG Academy<\/a> for more advanced training!<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this guide here : <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/11\/JUnitGuide.zip\">JUnitGuide.zip<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>EDITORIAL NOTE: We have provided plenty of JUnit tutorials here at Java Code Geeks, like JUnit Getting Started Example, JUnit Using Assertions and Annotations Example, JUnit Annotations Example and so on. However, we prefered to gather all the JUnit features in one detailed guide for the convenience of the reader. We hope you like it! &hellip;<\/p>\n","protected":false},"author":602,"featured_media":176,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[274,273,1039],"class_list":["post-31893","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-junit","tag-testing","tag-ultimate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JUnit Tutorial for Unit Testing \u2013 The ULTIMATE Guide (PDF Download)<\/title>\n<meta name=\"description\" content=\"Check out our detailed Junit Tutorial where we use Eclipse and run JUnit tests from command line! You can also download our FREE Junit Ultimate Guide!\" \/>\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\/2014\/11\/junit-tutorial-unit-testing.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JUnit Tutorial for Unit Testing \u2013 The ULTIMATE Guide (PDF Download)\" \/>\n<meta property=\"og:description\" content=\"Check out our detailed Junit Tutorial where we use Eclipse and run JUnit tests from command line! You can also download our FREE Junit Ultimate Guide!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.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=\"2014-11-10T14:00:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-05T14:01:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.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=\"Konstantina Dimtsa\" \/>\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=\"Konstantina Dimtsa\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"16 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.html\"},\"author\":{\"name\":\"Konstantina Dimtsa\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/55fef37826c5195bfa362d79276d8f60\"},\"headline\":\"JUnit Tutorial for Unit Testing \u2013 The ULTIMATE Guide (PDF Download)\",\"datePublished\":\"2014-11-10T14:00:28+00:00\",\"dateModified\":\"2023-12-05T14:01:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.html\"},\"wordCount\":3249,\"commentCount\":29,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"keywords\":[\"JUnit\",\"Testing\",\"Ultimate\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.html\",\"name\":\"JUnit Tutorial for Unit Testing \u2013 The ULTIMATE Guide (PDF Download)\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"datePublished\":\"2014-11-10T14:00:28+00:00\",\"dateModified\":\"2023-12-05T14:01:59+00:00\",\"description\":\"Check out our detailed Junit Tutorial where we use Eclipse and run JUnit tests from command line! You can also download our FREE Junit Ultimate Guide!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/11\\\/junit-tutorial-unit-testing.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\":\"Core Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/core-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"JUnit Tutorial for Unit Testing \u2013 The ULTIMATE Guide (PDF Download)\"}]},{\"@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\\\/55fef37826c5195bfa362d79276d8f60\",\"name\":\"Konstantina Dimtsa\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4e56af992f66e97fb1cd9633a1c25e33b866c86992e74759a4b05a4160e31bc9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4e56af992f66e97fb1cd9633a1c25e33b866c86992e74759a4b05a4160e31bc9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4e56af992f66e97fb1cd9633a1c25e33b866c86992e74759a4b05a4160e31bc9?s=96&d=mm&r=g\",\"caption\":\"Konstantina Dimtsa\"},\"description\":\"Konstantina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she is currently pursuing M.Sc studies in Advanced Information Systems at the same department. She is also working as a research associate for NKUA in the field of telecommunications. Her main interests lie in software engineering, web applications, databases and telecommunications.\",\"sameAs\":[\"http:\\\/\\\/www.javacodegeeks.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/konstantina-dimtsa\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JUnit Tutorial for Unit Testing \u2013 The ULTIMATE Guide (PDF Download)","description":"Check out our detailed Junit Tutorial where we use Eclipse and run JUnit tests from command line! You can also download our FREE Junit Ultimate Guide!","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\/2014\/11\/junit-tutorial-unit-testing.html","og_locale":"en_US","og_type":"article","og_title":"JUnit Tutorial for Unit Testing \u2013 The ULTIMATE Guide (PDF Download)","og_description":"Check out our detailed Junit Tutorial where we use Eclipse and run JUnit tests from command line! You can also download our FREE Junit Ultimate Guide!","og_url":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-11-10T14:00:28+00:00","article_modified_time":"2023-12-05T14:01:59+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","type":"image\/jpeg"}],"author":"Konstantina Dimtsa","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Konstantina Dimtsa","Est. reading time":"16 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html"},"author":{"name":"Konstantina Dimtsa","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/55fef37826c5195bfa362d79276d8f60"},"headline":"JUnit Tutorial for Unit Testing \u2013 The ULTIMATE Guide (PDF Download)","datePublished":"2014-11-10T14:00:28+00:00","dateModified":"2023-12-05T14:01:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html"},"wordCount":3249,"commentCount":29,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","keywords":["JUnit","Testing","Ultimate"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html","url":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html","name":"JUnit Tutorial for Unit Testing \u2013 The ULTIMATE Guide (PDF Download)","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","datePublished":"2014-11-10T14:00:28+00:00","dateModified":"2023-12-05T14:01:59+00:00","description":"Check out our detailed Junit Tutorial where we use Eclipse and run JUnit tests from command line! You can also download our FREE Junit Ultimate Guide!","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/11\/junit-tutorial-unit-testing.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":"Core Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/core-java"},{"@type":"ListItem","position":4,"name":"JUnit Tutorial for Unit Testing \u2013 The ULTIMATE Guide (PDF Download)"}]},{"@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\/55fef37826c5195bfa362d79276d8f60","name":"Konstantina Dimtsa","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4e56af992f66e97fb1cd9633a1c25e33b866c86992e74759a4b05a4160e31bc9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4e56af992f66e97fb1cd9633a1c25e33b866c86992e74759a4b05a4160e31bc9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4e56af992f66e97fb1cd9633a1c25e33b866c86992e74759a4b05a4160e31bc9?s=96&d=mm&r=g","caption":"Konstantina Dimtsa"},"description":"Konstantina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she is currently pursuing M.Sc studies in Advanced Information Systems at the same department. She is also working as a research associate for NKUA in the field of telecommunications. Her main interests lie in software engineering, web applications, databases and telecommunications.","sameAs":["http:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/konstantina-dimtsa"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/31893","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\/602"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=31893"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/31893\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/176"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=31893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=31893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=31893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}