{"id":96,"date":"2024-07-30T06:49:54","date_gmt":"2024-07-30T06:49:54","guid":{"rendered":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/chapter\/using-gradle-projects-and-testng-with-vscode\/"},"modified":"2026-03-16T14:29:36","modified_gmt":"2026-03-16T14:29:36","slug":"using-gradle-projects-and-testng-with-vscode","status":"publish","type":"chapter","link":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/chapter\/using-gradle-projects-and-testng-with-vscode\/","title":{"raw":"Using Gradle Projects and TestNG with VSCode","rendered":"Using Gradle Projects and TestNG with VSCode"},"content":{"raw":"<div class=\"using-gradle-projects-and-testng-with-vscode\">\n<p class=\"import-Normal\"><a class=\"rId66\" href=\"https:\/\/boisestate.hosted.panopto.com\/Panopto\/Pages\/Viewer.aspx?id=7630420b-bd64-4902-b006-b0ef0132218d\">Lecture: Running Gradle Projects<\/a><\/p>\n<p class=\"import-Normal\"><a class=\"rId67\" href=\"https:\/\/boisestate.hosted.panopto.com\/Panopto\/Pages\/Viewer.aspx?id=42821667-9b08-4024-90d2-b0ef013addbf\">Lecture: Using TestNG with VSCode<\/a><\/p>\n\n<h3><a id=\"_sv37n28j2adh\" href=\"\"><\/a>Intro to Gradle<\/h3>\n<p class=\"import-Normal\">This semester, we're using a build tool called Gradle. Gradle allows you to specify exactly how your project should be built - which version of Java to use, which source files to include, which testing framework to use, etc. If you're curious, you can see the build file in <em>app\/build.gradle<\/em>. Don't modify the file, though!<\/p>\n\n<h3><a id=\"_rrhqu2c63hic\" href=\"\"><\/a>Using Gradle Tasks<\/h3>\n<p class=\"import-Normal\">There are a few ways to run a Gradle project in VS Code. If your project has a main method, you should see \"Run\" appear above the main method. However, not all of your projects will have a main method.<\/p>\n<p class=\"import-Normal\">Gradle has several \"tasks\" built in. We'll use the following tasks:<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt;text-indent: 18pt\"><em>build<\/em> - compiles your project and runs the tests<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 72pt;text-indent: 18pt\"><em>build -x test<\/em> - compiles your project without running tests<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt;text-indent: 18pt\"><em>run<\/em> - runs the project, if it has a main method<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt;text-indent: 18pt\"><em>test<\/em> - runs the tests<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt;text-indent: 18pt\"><em>clean <\/em>- removes all the temporary build files (like .class files)<\/p>\n<p class=\"import-Normal\">You can run tasks individually or multiple at a time.<\/p>\n\n<h4><a id=\"_1n7xi963ydcg\" href=\"\"><\/a>Build<\/h4>\n<p class=\"import-Normal\">To run a Gradle task in VS Code, click on the elephant icon on the left side. At the top next to GRADLE PROJECTS, the first icon will let you run a task.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2024\/07\/image21-1.png\" alt=\"image\" width=\"384px\" height=\"438.563044619423px\"><\/p>\n<p class=\"import-Normal\">To compile your project, type <em>build -x test<\/em> in the box that pops up when you click the <em>Run a Gradle Build<\/em> icon. Press Enter to run the command.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image51-1.png\" alt=\"image\" width=\"576px\" height=\"174.24px\"><\/p>\n<p class=\"import-Normal\">This will compile your code, but not test it. The output will appear in the terminal.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image97-1.png\" alt=\"image\" width=\"576px\" height=\"538.56px\"><\/p>\n<p class=\"import-Normal\">If you have errors, the errors will appear in the terminal as well.<\/p>\n\n<h4><a id=\"_eyb3nu2foi72\" href=\"\"><\/a>Run<\/h4>\n<p class=\"import-Normal\">If your project has a main method, you can run it by entering <em>run<\/em> in the <em>Gradle build<\/em> box. If you haven't previously built your project, it will first build and then run.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image74-1.png\" alt=\"image\" width=\"384px\" height=\"119.68px\"><\/p>\n<p class=\"import-Normal\">The output will appear in the terminal.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image46-1.png\" alt=\"image\" width=\"384px\" height=\"268.291338582677px\"><\/p>\n\n<h4><a id=\"_mbssr2pdpi68\" href=\"\"><\/a>Debug<\/h4>\n<p class=\"import-Normal\">To debug the main method, it's easiest to run the task using the GUI.<\/p>\n<p class=\"import-Normal\">Expand the <em>Tasks<\/em> folder, then expand <em>application.<\/em> Hover over the <em>run<\/em> task and two icons should appear. The first has a bug with a play button - that's your debugger.<\/p>\n<p class=\"import-Normal\">Note you could run the <em>run<\/em> task by clicking the play button next to <em>run.<\/em><\/p>\n<p class=\"import-Normal\">Make sure you set breakpoints by clicking on the line number where you want to break. A red dot should appear.<\/p>\n\n<h2><a id=\"_j9syjantx6au\" href=\"\"><\/a><strong><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image39.png\" alt=\"image\" width=\"334.350446194226px\" height=\"604.268661417323px\"><\/strong><\/h2>\n<p class=\"import-Normal\">Using the debugger is covered in a different document.<\/p>\n\n<h4><a id=\"_oz2aqo2aqj8\" href=\"\"><\/a>Test<\/h4>\n<p class=\"import-Normal\">To run your tests, enter <em>clean test.<\/em><\/p>\n<p class=\"import-Normal\">Running clean before testing ensures that the test output appears.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image64-1.png\" alt=\"image\" width=\"384px\" height=\"164.056377952756px\"><\/p>\n<p class=\"import-Normal\">The output will appear in the terminal. VS Code offers several ways to run Gradle tests; those other options will be covered in a different document.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image96-1.png\" alt=\"image\" width=\"384px\" height=\"314.992230971129px\"><\/p>\n\n<h4><a id=\"_6np5odyem929\" href=\"\"><\/a>Clean<\/h4>\n<p class=\"import-Normal\">Cleaning the project removes all of the temporary files and folders that are created during the build process. You can clean a project to force it to rebuild, which can sometimes fix weird errors. You may also want to clean your project before you commit your files to GitHub so you don't push a bunch of files you don't need and it's easier to see what needs to be committed.<\/p>\n<p class=\"import-Normal\">To clean, enter <em>clean<\/em> in the <em>Gradle Build <\/em>text box.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image87-1.png\" alt=\"image\" width=\"384px\" height=\"133.255118110236px\"><\/p>\n<p class=\"import-Normal\">If all goes well, you'll get a pretty simple output.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image72-1.png\" alt=\"image\" width=\"384px\" height=\"182.659422572178px\"><\/p>\n\n<h3><a id=\"_m0rj9f5krn6o\" href=\"\"><\/a>Introduction To Running TestNG Tests with VSCode and Gradle<\/h3>\n<p class=\"import-Normal\">VS Code has a pretty nifty testing interface. If you just want to run all of the tests, you can use the <em>test<\/em> task. But you can also run specific tests and debug tests by using the test interface.<\/p>\n\n<h4><a id=\"_4eaaeb333ab9\" href=\"\"><\/a>Test Gradle Task<\/h4>\n<p class=\"import-Normal\">To run your tests, enter <em>clean test.<\/em><\/p>\n<p class=\"import-Normal\">Running clean before testing ensures that the test output appears.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image64-2.png\" alt=\"image\" width=\"384px\" height=\"164.056377952756px\"><\/p>\n<p class=\"import-Normal\">The output will appear in the terminal. VS Code offers several ways to run Gradle tests; those other options will be covered in a different document.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image96-2.png\" alt=\"image\" width=\"384px\" height=\"314.992230971129px\"><\/p>\n\n<h4><a id=\"_ybl6x4l0euhf\" href=\"\"><\/a>VS Code Testing View<\/h4>\n<p class=\"import-Normal\">To open the Testing View, click on the beaker icon on the left side. Expand the menus until you see your test files. You can click the arrow by the test file to see a list of tests in each file.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image10-1.png\" alt=\"image\" width=\"384px\" height=\"319.168818897638px\"><\/p>\n\n<h4><a id=\"_8eswelx4atlv\" href=\"\"><\/a>Run All Tests or Some Tests<\/h4>\n<p class=\"import-Normal\">If you hover over each line, you'll see three icons: Run, Debug, and Go to Test.<\/p>\n<p class=\"import-Normal\">Run and Debug do exactly as they say - run or debug whatever you're hovering over. Go to Test will take you to the implementation in the test file.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image5-1.png\" alt=\"image\" width=\"384px\" height=\"110.994645669291px\"><\/p>\n<p class=\"import-Normal\">In this scenario, I have two test classes - LabTest and MainTest. If I run <em>app<\/em>, then all of the test classes' tests will run. if I run <em>MainTest<\/em>, then all of the test methods inside <em>MainTest<\/em> will run. If I run a specific method, then only that method will be run.<\/p>\n<p class=\"import-Normal\">For example, if I click on <em>Run<\/em> next to <em>testGetGreeting, <\/em>the only method that runs is <em>testGetGreeting<\/em>. Note there isn't a checkmark or an X next to <em>LabTest <\/em>or <em>testGetPlanet<\/em>; those tests didn't run!<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image114.png\" alt=\"image\" width=\"384px\" height=\"282.911706036745px\"><\/p>\n<p class=\"import-Normal\">If the test passed, you'll see a green check mark next to it. If the test failed (or any test inside the test class failed), you'll see a red X next to it. In the picture below, all of the <em>LabTest <\/em>methods passed. In <em>MainTest<\/em>, one test passed and one test failed. Because of the failing test, it shows that <em>MainTest<\/em> has failed tests, package <em>lab<\/em> has failed tests, and the entire project <em>app<\/em> has failed tests.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image91-1.png\" alt=\"image\" width=\"384px\" height=\"299.428556430446px\"><\/p>\n\n<h4><a id=\"_dy63mvdv3jj4\" href=\"\"><\/a>Failing Tests<\/h4>\n<p class=\"import-Normal\">If a test fails, you'll get an error pop up at the line that failed. If you click on the name of the test that failed in the Test Result panel (at the bottom), you can read the error message. The first line of the error message tells you what was expected and what the test actually got.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image20-1.png\" alt=\"image\" width=\"2048px\" height=\"979px\"><\/p>\n<p class=\"import-Normal\">In this case, it may be easier to execute the Gradle <em>clean test<\/em> tasks so you can clearly read the error messages:<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image18-1.png\" alt=\"image\" width=\"576px\" height=\"336.96px\"><\/p>\n\n<h2><\/h2>\n<h4><a id=\"_h5pv9k9vi19y\" href=\"\"><\/a>Debugging Tests<\/h4>\n<p class=\"import-Normal\">To debug, you first need to set a breakpoint, then click \"Debug test\". You can use the handy \"Go to Test\" to take you right to the method where you want to set your breakpoint!<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image66-1.png\" alt=\"image\" width=\"384px\" height=\"112.457112860892px\"><\/p>\n<p class=\"import-Normal\">Set a breakpoint by clicking just to the left of the line number.<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image77-1.png\" alt=\"image\" width=\"384px\" height=\"325.12px\"><\/p>\n<p class=\"import-Normal\">That's where the program will stop so you can inspect the variable values<\/p>\n<p class=\"import-Normal\"><img src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image53-1.png\" alt=\"image\" width=\"576px\" height=\"216px\"><\/p>\n<p class=\"import-Normal\"><\/p>\n\n<\/div>","rendered":"<div class=\"using-gradle-projects-and-testng-with-vscode\">\n<p class=\"import-Normal\"><a class=\"rId66\" href=\"https:\/\/boisestate.hosted.panopto.com\/Panopto\/Pages\/Viewer.aspx?id=7630420b-bd64-4902-b006-b0ef0132218d\">Lecture: Running Gradle Projects<\/a><\/p>\n<p class=\"import-Normal\"><a class=\"rId67\" href=\"https:\/\/boisestate.hosted.panopto.com\/Panopto\/Pages\/Viewer.aspx?id=42821667-9b08-4024-90d2-b0ef013addbf\">Lecture: Using TestNG with VSCode<\/a><\/p>\n<h3><a id=\"_sv37n28j2adh\" href=\"\"><\/a>Intro to Gradle<\/h3>\n<p class=\"import-Normal\">This semester, we&#8217;re using a build tool called Gradle. Gradle allows you to specify exactly how your project should be built &#8211; which version of Java to use, which source files to include, which testing framework to use, etc. If you&#8217;re curious, you can see the build file in <em>app\/build.gradle<\/em>. Don&#8217;t modify the file, though!<\/p>\n<h3><a id=\"_rrhqu2c63hic\" href=\"\"><\/a>Using Gradle Tasks<\/h3>\n<p class=\"import-Normal\">There are a few ways to run a Gradle project in VS Code. If your project has a main method, you should see &#8220;Run&#8221; appear above the main method. However, not all of your projects will have a main method.<\/p>\n<p class=\"import-Normal\">Gradle has several &#8220;tasks&#8221; built in. We&#8217;ll use the following tasks:<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt;text-indent: 18pt\"><em>build<\/em> &#8211; compiles your project and runs the tests<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 72pt;text-indent: 18pt\"><em>build -x test<\/em> &#8211; compiles your project without running tests<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt;text-indent: 18pt\"><em>run<\/em> &#8211; runs the project, if it has a main method<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt;text-indent: 18pt\"><em>test<\/em> &#8211; runs the tests<\/p>\n<p class=\"import-Normal\" style=\"margin-left: 36pt;text-indent: 18pt\"><em>clean <\/em>&#8211; removes all the temporary build files (like .class files)<\/p>\n<p class=\"import-Normal\">You can run tasks individually or multiple at a time.<\/p>\n<h4><a id=\"_1n7xi963ydcg\" href=\"\"><\/a>Build<\/h4>\n<p class=\"import-Normal\">To run a Gradle task in VS Code, click on the elephant icon on the left side. At the top next to GRADLE PROJECTS, the first icon will let you run a task.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2024\/07\/image21-1.png\" alt=\"image\" width=\"384px\" height=\"438.563044619423px\" \/><\/p>\n<p class=\"import-Normal\">To compile your project, type <em>build -x test<\/em> in the box that pops up when you click the <em>Run a Gradle Build<\/em> icon. Press Enter to run the command.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image51-1.png\" alt=\"image\" width=\"576px\" height=\"174.24px\" \/><\/p>\n<p class=\"import-Normal\">This will compile your code, but not test it. The output will appear in the terminal.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image97-1.png\" alt=\"image\" width=\"576px\" height=\"538.56px\" \/><\/p>\n<p class=\"import-Normal\">If you have errors, the errors will appear in the terminal as well.<\/p>\n<h4><a id=\"_eyb3nu2foi72\" href=\"\"><\/a>Run<\/h4>\n<p class=\"import-Normal\">If your project has a main method, you can run it by entering <em>run<\/em> in the <em>Gradle build<\/em> box. If you haven&#8217;t previously built your project, it will first build and then run.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image74-1.png\" alt=\"image\" width=\"384px\" height=\"119.68px\" \/><\/p>\n<p class=\"import-Normal\">The output will appear in the terminal.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image46-1.png\" alt=\"image\" width=\"384px\" height=\"268.291338582677px\" \/><\/p>\n<h4><a id=\"_mbssr2pdpi68\" href=\"\"><\/a>Debug<\/h4>\n<p class=\"import-Normal\">To debug the main method, it&#8217;s easiest to run the task using the GUI.<\/p>\n<p class=\"import-Normal\">Expand the <em>Tasks<\/em> folder, then expand <em>application.<\/em> Hover over the <em>run<\/em> task and two icons should appear. The first has a bug with a play button &#8211; that&#8217;s your debugger.<\/p>\n<p class=\"import-Normal\">Note you could run the <em>run<\/em> task by clicking the play button next to <em>run.<\/em><\/p>\n<p class=\"import-Normal\">Make sure you set breakpoints by clicking on the line number where you want to break. A red dot should appear.<\/p>\n<h2><a id=\"_j9syjantx6au\" href=\"\"><\/a><strong><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image39.png\" alt=\"image\" width=\"334.350446194226px\" height=\"604.268661417323px\" \/><\/strong><\/h2>\n<p class=\"import-Normal\">Using the debugger is covered in a different document.<\/p>\n<h4><a id=\"_oz2aqo2aqj8\" href=\"\"><\/a>Test<\/h4>\n<p class=\"import-Normal\">To run your tests, enter <em>clean test.<\/em><\/p>\n<p class=\"import-Normal\">Running clean before testing ensures that the test output appears.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image64-1.png\" alt=\"image\" width=\"384px\" height=\"164.056377952756px\" \/><\/p>\n<p class=\"import-Normal\">The output will appear in the terminal. VS Code offers several ways to run Gradle tests; those other options will be covered in a different document.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image96-1.png\" alt=\"image\" width=\"384px\" height=\"314.992230971129px\" \/><\/p>\n<h4><a id=\"_6np5odyem929\" href=\"\"><\/a>Clean<\/h4>\n<p class=\"import-Normal\">Cleaning the project removes all of the temporary files and folders that are created during the build process. You can clean a project to force it to rebuild, which can sometimes fix weird errors. You may also want to clean your project before you commit your files to GitHub so you don&#8217;t push a bunch of files you don&#8217;t need and it&#8217;s easier to see what needs to be committed.<\/p>\n<p class=\"import-Normal\">To clean, enter <em>clean<\/em> in the <em>Gradle Build <\/em>text box.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image87-1.png\" alt=\"image\" width=\"384px\" height=\"133.255118110236px\" \/><\/p>\n<p class=\"import-Normal\">If all goes well, you&#8217;ll get a pretty simple output.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image72-1.png\" alt=\"image\" width=\"384px\" height=\"182.659422572178px\" \/><\/p>\n<h3><a id=\"_m0rj9f5krn6o\" href=\"\"><\/a>Introduction To Running TestNG Tests with VSCode and Gradle<\/h3>\n<p class=\"import-Normal\">VS Code has a pretty nifty testing interface. If you just want to run all of the tests, you can use the <em>test<\/em> task. But you can also run specific tests and debug tests by using the test interface.<\/p>\n<h4><a id=\"_4eaaeb333ab9\" href=\"\"><\/a>Test Gradle Task<\/h4>\n<p class=\"import-Normal\">To run your tests, enter <em>clean test.<\/em><\/p>\n<p class=\"import-Normal\">Running clean before testing ensures that the test output appears.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image64-2.png\" alt=\"image\" width=\"384px\" height=\"164.056377952756px\" \/><\/p>\n<p class=\"import-Normal\">The output will appear in the terminal. VS Code offers several ways to run Gradle tests; those other options will be covered in a different document.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image96-2.png\" alt=\"image\" width=\"384px\" height=\"314.992230971129px\" \/><\/p>\n<h4><a id=\"_ybl6x4l0euhf\" href=\"\"><\/a>VS Code Testing View<\/h4>\n<p class=\"import-Normal\">To open the Testing View, click on the beaker icon on the left side. Expand the menus until you see your test files. You can click the arrow by the test file to see a list of tests in each file.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image10-1.png\" alt=\"image\" width=\"384px\" height=\"319.168818897638px\" \/><\/p>\n<h4><a id=\"_8eswelx4atlv\" href=\"\"><\/a>Run All Tests or Some Tests<\/h4>\n<p class=\"import-Normal\">If you hover over each line, you&#8217;ll see three icons: Run, Debug, and Go to Test.<\/p>\n<p class=\"import-Normal\">Run and Debug do exactly as they say &#8211; run or debug whatever you&#8217;re hovering over. Go to Test will take you to the implementation in the test file.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image5-1.png\" alt=\"image\" width=\"384px\" height=\"110.994645669291px\" \/><\/p>\n<p class=\"import-Normal\">In this scenario, I have two test classes &#8211; LabTest and MainTest. If I run <em>app<\/em>, then all of the test classes&#8217; tests will run. if I run <em>MainTest<\/em>, then all of the test methods inside <em>MainTest<\/em> will run. If I run a specific method, then only that method will be run.<\/p>\n<p class=\"import-Normal\">For example, if I click on <em>Run<\/em> next to <em>testGetGreeting, <\/em>the only method that runs is <em>testGetGreeting<\/em>. Note there isn&#8217;t a checkmark or an X next to <em>LabTest <\/em>or <em>testGetPlanet<\/em>; those tests didn&#8217;t run!<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image114.png\" alt=\"image\" width=\"384px\" height=\"282.911706036745px\" \/><\/p>\n<p class=\"import-Normal\">If the test passed, you&#8217;ll see a green check mark next to it. If the test failed (or any test inside the test class failed), you&#8217;ll see a red X next to it. In the picture below, all of the <em>LabTest <\/em>methods passed. In <em>MainTest<\/em>, one test passed and one test failed. Because of the failing test, it shows that <em>MainTest<\/em> has failed tests, package <em>lab<\/em> has failed tests, and the entire project <em>app<\/em> has failed tests.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image91-1.png\" alt=\"image\" width=\"384px\" height=\"299.428556430446px\" \/><\/p>\n<h4><a id=\"_dy63mvdv3jj4\" href=\"\"><\/a>Failing Tests<\/h4>\n<p class=\"import-Normal\">If a test fails, you&#8217;ll get an error pop up at the line that failed. If you click on the name of the test that failed in the Test Result panel (at the bottom), you can read the error message. The first line of the error message tells you what was expected and what the test actually got.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image20-1.png\" alt=\"image\" width=\"2048px\" height=\"979px\" \/><\/p>\n<p class=\"import-Normal\">In this case, it may be easier to execute the Gradle <em>clean test<\/em> tasks so you can clearly read the error messages:<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image18-1.png\" alt=\"image\" width=\"576px\" height=\"336.96px\" \/><\/p>\n<h2><\/h2>\n<h4><a id=\"_h5pv9k9vi19y\" href=\"\"><\/a>Debugging Tests<\/h4>\n<p class=\"import-Normal\">To debug, you first need to set a breakpoint, then click &#8220;Debug test&#8221;. You can use the handy &#8220;Go to Test&#8221; to take you right to the method where you want to set your breakpoint!<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image66-1.png\" alt=\"image\" width=\"384px\" height=\"112.457112860892px\" \/><\/p>\n<p class=\"import-Normal\">Set a breakpoint by clicking just to the left of the line number.<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image77-1.png\" alt=\"image\" width=\"384px\" height=\"325.12px\" \/><\/p>\n<p class=\"import-Normal\">That&#8217;s where the program will stop so you can inspect the variable values<\/p>\n<p class=\"import-Normal\"><img decoding=\"async\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/21\/2026\/03\/image53-1.png\" alt=\"image\" width=\"576px\" height=\"216px\" \/><\/p>\n<p class=\"import-Normal\">\n<\/div>\n","protected":false},"author":1,"menu_order":7,"template":"","meta":{"pb_show_title":"","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[49],"contributor":[],"license":[],"class_list":["post-96","chapter","type-chapter","status-publish","hentry","chapter-type-numberless"],"part":18,"_links":{"self":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":1,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters\/96\/revisions"}],"predecessor-version":[{"id":97,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters\/96\/revisions\/97"}],"part":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/parts\/18"}],"metadata":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters\/96\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/media?parent=96"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapter-type?post=96"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/contributor?post=96"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/license?post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}