<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Karl Rombauts on Medium]]></title>
        <description><![CDATA[Stories by Karl Rombauts on Medium]]></description>
        <link>https://medium.com/@karlrombauts?source=rss-c0e0fb00d822------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Ndot9X8sMtGEgY2S</url>
            <title>Stories by Karl Rombauts on Medium</title>
            <link>https://medium.com/@karlrombauts?source=rss-c0e0fb00d822------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 02:47:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@karlrombauts/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Treewidth: How all graphs are trees in disguise!]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@karlrombauts/treewidth-how-all-graphs-are-trees-in-disguise-ec699b69e2fb?source=rss-c0e0fb00d822------2"><img src="https://cdn-images-1.medium.com/max/1550/1*GyyZTYE4aXBX5UuKzkOJ7A.png" width="1550"></a></p><p class="medium-feed-snippet">In order to better understand graphs, we commonly describe them using several statistics and properties such as the number of edges and&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@karlrombauts/treewidth-how-all-graphs-are-trees-in-disguise-ec699b69e2fb?source=rss-c0e0fb00d822------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@karlrombauts/treewidth-how-all-graphs-are-trees-in-disguise-ec699b69e2fb?source=rss-c0e0fb00d822------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec699b69e2fb</guid>
            <category><![CDATA[graph-theory]]></category>
            <category><![CDATA[np-complete]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[combinatorics]]></category>
            <dc:creator><![CDATA[Karl Rombauts]]></dc:creator>
            <pubDate>Tue, 29 Nov 2022 06:37:38 GMT</pubDate>
            <atom:updated>2022-11-29T06:37:38.516Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Making Generative Art With Triangles]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@karlrombauts/making-generative-art-with-triangles-273702d20f42?source=rss-c0e0fb00d822------2"><img src="https://cdn-images-1.medium.com/max/1068/1*N69jJH97_DMes1segGoGlA.png" width="1068"></a></p><p class="medium-feed-snippet">Last week in my advanced algorithms class, our lecturer posed a simple puzzle to play around with:</p><p class="medium-feed-link"><a href="https://medium.com/@karlrombauts/making-generative-art-with-triangles-273702d20f42?source=rss-c0e0fb00d822------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@karlrombauts/making-generative-art-with-triangles-273702d20f42?source=rss-c0e0fb00d822------2</link>
            <guid isPermaLink="false">https://medium.com/p/273702d20f42</guid>
            <category><![CDATA[generative-art]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[alan-turing]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Karl Rombauts]]></dc:creator>
            <pubDate>Sun, 14 Aug 2022 18:26:40 GMT</pubDate>
            <atom:updated>2022-08-15T04:04:51.597Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[An Introduction to Quantum Computing: Understanding Shor’s Algorithm]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@karlrombauts/an-introduction-to-quantum-computing-understanding-shors-algorithm-90c98fde3adb?source=rss-c0e0fb00d822------2"><img src="https://cdn-images-1.medium.com/max/2600/0*xJ_ym05Vve7UhQ-c" width="5184"></a></p><p class="medium-feed-snippet">This article aims to provide an elementary explanation of how Shor&#x2019;s Algorithm works. Although elementary, meaning there is very little&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@karlrombauts/an-introduction-to-quantum-computing-understanding-shors-algorithm-90c98fde3adb?source=rss-c0e0fb00d822------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@karlrombauts/an-introduction-to-quantum-computing-understanding-shors-algorithm-90c98fde3adb?source=rss-c0e0fb00d822------2</link>
            <guid isPermaLink="false">https://medium.com/p/90c98fde3adb</guid>
            <category><![CDATA[shors-algorithm]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[quantum-computing]]></category>
            <category><![CDATA[entanglement]]></category>
            <dc:creator><![CDATA[Karl Rombauts]]></dc:creator>
            <pubDate>Fri, 29 Oct 2021 04:23:51 GMT</pubDate>
            <atom:updated>2021-10-29T04:23:51.793Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building an 8-bit computer in Logisim (Part 4 — Status Flags)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@karlrombauts/building-an-8-bit-computer-in-logisim-part-4-status-flags-c41d8ca44542?source=rss-c0e0fb00d822------2"><img src="https://cdn-images-1.medium.com/max/2600/1*17OOB-l-x1EfPsTweXtUHg.png" width="3084"></a></p><p class="medium-feed-snippet">Now that we have our main arithmetic sorted, in this part, we will be looking at how to build the Arithmetic Logic Unit (ALU).</p><p class="medium-feed-link"><a href="https://medium.com/@karlrombauts/building-an-8-bit-computer-in-logisim-part-4-status-flags-c41d8ca44542?source=rss-c0e0fb00d822------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@karlrombauts/building-an-8-bit-computer-in-logisim-part-4-status-flags-c41d8ca44542?source=rss-c0e0fb00d822------2</link>
            <guid isPermaLink="false">https://medium.com/p/c41d8ca44542</guid>
            <category><![CDATA[logic]]></category>
            <category><![CDATA[binary]]></category>
            <category><![CDATA[flags]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[alu]]></category>
            <dc:creator><![CDATA[Karl Rombauts]]></dc:creator>
            <pubDate>Wed, 01 Jul 2020 15:41:07 GMT</pubDate>
            <atom:updated>2020-07-01T15:56:28.300Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building an 8-bit computer in Logisim (Part 3 — Basic ALU)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@karlrombauts/building-an-8-bit-computer-in-logisim-part-3-basic-alu-29a7dd9d569?source=rss-c0e0fb00d822------2"><img src="https://cdn-images-1.medium.com/max/698/1*TDSfNh4X4NzzSUkh6lsyzg.gif" width="698"></a></p><p class="medium-feed-snippet">This is the third article in a series. If you haven&#x2019;t read part 1 and 2, you can find them here:</p><p class="medium-feed-link"><a href="https://medium.com/@karlrombauts/building-an-8-bit-computer-in-logisim-part-3-basic-alu-29a7dd9d569?source=rss-c0e0fb00d822------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@karlrombauts/building-an-8-bit-computer-in-logisim-part-3-basic-alu-29a7dd9d569?source=rss-c0e0fb00d822------2</link>
            <guid isPermaLink="false">https://medium.com/p/29a7dd9d569</guid>
            <category><![CDATA[alu]]></category>
            <category><![CDATA[logic]]></category>
            <category><![CDATA[binary]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Karl Rombauts]]></dc:creator>
            <pubDate>Tue, 23 Jun 2020 07:05:01 GMT</pubDate>
            <atom:updated>2020-07-01T15:58:53.003Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building an 8-bit computer in Logisim (Part 2— Arithmetic)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@karlrombauts/building-an-8-bit-computer-in-logisim-part-2-arithmetic-ae7861c82e79?source=rss-c0e0fb00d822------2"><img src="https://cdn-images-1.medium.com/max/2384/1*COlG09IVqDEAojfhEVxqJg.png" width="2384"></a></p><p class="medium-feed-snippet">In this part, we will be covering how to do all the standard arithmetic operations, addition, subtraction, multiplication, and division&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@karlrombauts/building-an-8-bit-computer-in-logisim-part-2-arithmetic-ae7861c82e79?source=rss-c0e0fb00d822------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@karlrombauts/building-an-8-bit-computer-in-logisim-part-2-arithmetic-ae7861c82e79?source=rss-c0e0fb00d822------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae7861c82e79</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[logic]]></category>
            <category><![CDATA[arithmetic]]></category>
            <category><![CDATA[binary]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Karl Rombauts]]></dc:creator>
            <pubDate>Sat, 25 Apr 2020 06:34:21 GMT</pubDate>
            <atom:updated>2020-07-01T16:01:33.024Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building an 8-bit computer in Logisim (Part 1 — Building Blocks)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@karlrombauts/building-an-8-bit-computer-in-logisim-part-1-building-blocks-a4f1e5ea0d03?source=rss-c0e0fb00d822------2"><img src="https://cdn-images-1.medium.com/max/2600/1*XG4_RtPi5SJrTq4YPduPIQ.png" width="3056"></a></p><p class="medium-feed-snippet">Last semester I built a basic 8-bit computer in Logisim. This all started because of a course that I took last semester at uni called&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@karlrombauts/building-an-8-bit-computer-in-logisim-part-1-building-blocks-a4f1e5ea0d03?source=rss-c0e0fb00d822------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@karlrombauts/building-an-8-bit-computer-in-logisim-part-1-building-blocks-a4f1e5ea0d03?source=rss-c0e0fb00d822------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4f1e5ea0d03</guid>
            <category><![CDATA[computers]]></category>
            <category><![CDATA[logisim]]></category>
            <category><![CDATA[cpu]]></category>
            <category><![CDATA[logic]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Karl Rombauts]]></dc:creator>
            <pubDate>Fri, 10 Apr 2020 11:44:59 GMT</pubDate>
            <atom:updated>2020-07-01T16:02:21.242Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Setting Up Unit Testing For Java In VS Code (with Maven)]]></title>
            <link>https://medium.com/@karlrombauts/setting-up-unit-testing-for-java-in-vs-code-with-maven-3dc75579122f?source=rss-c0e0fb00d822------2</link>
            <guid isPermaLink="false">https://medium.com/p/3dc75579122f</guid>
            <category><![CDATA[junit]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[code-coverage]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Karl Rombauts]]></dc:creator>
            <pubDate>Sun, 05 Apr 2020 07:09:36 GMT</pubDate>
            <atom:updated>2020-05-06T11:47:26.888Z</atom:updated>
            <content:encoded><![CDATA[<p>Today I found out about this really neat extension for VS Code called code gutters <a href="https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters">Coverage Gutters</a>. So I thought cool let’s install that. A few hours later down the rabbit hole, I have learnt a lot about setting up unit testing in VS Code for Java. So I thought, why not share what I learnt for others who want to do the same.</p><h3>Step 1: Install Relevant Java Extensions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*TgpWh-vrs4R9BdAltx4bPA.png" /></figure><p>The <a href="https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack">Java Extension Pack</a> is basically everything that you are going to need to get up and running with Java in VS Code. This pack will install the following extensions for you. Feel free to also install them individually if you like</p><ul><li><a href="https://marketplace.visualstudio.com/items?itemName=redhat.java">Language Support for Java™ by Red Hat</a></li><li><a href="https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug">Debugger for Java</a></li><li><a href="https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test">Java Test Runner</a></li><li><a href="https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven">Maven for Java</a></li><li><a href="https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-dependency">Java Dependency Viewer</a></li><li><a href="https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode">Visual Studio IntelliCode</a></li></ul><p>And then we will obviously need the <a href="https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters">Coverage Gutters</a> extension also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*vB8Y1MYhj8snJLYkwgjdDw.png" /></figure><p>Cool, that is all there is to it for extensions. Let’s move on to the next part!</p><h3>Step 2: Let’s start a new Java project</h3><p>We will be using Maven for the rest of this article. If you haven’t used maven before here is a <a href="https://www.freecodecamp.org/news/how-to-get-started-with-maven-36851d8cfd96/">quick guide</a> by free code camp.</p><p>The <a href="https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven">Maven for Java</a> extension that came bundled in the <a href="https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack">Java Extension Pack</a> makes setting up a new Maven project super simple! just type ctrl/cmd + shift + p to bring up the command palette. and select <strong>Maven: Create Maven Project</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JH5nDdLorHeq567jYEMvzg.png" /></figure><p>Then you will be prompted to select an archetype. If you don’t know, an archetype is like a basic template that installs all the things that you might need and sets up your projects for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V5peVzT91PvmWeBJAB7KrA.png" /></figure><p>We will be using the <strong>maven-archetype-quickstart</strong>. It will then prompt you for a version number. Just select the latest one, at the time of writing the latest version is 1.4.</p><p>It will then prompt you to select a destination folder. This is the folder that will contain your project folder. In my case, I choose my java-projects folder as the destination.</p><p>At this point, a terminal should pop up, and your project will start building. Once that is done, it will prompt you for some details.</p><pre>Define value for property &#39;groupId&#39;: com.[your-domain].[project-name]</pre><p>The groupId is meant to be a unique value for your project. So using your domain name (if you have one) is usually standard practice. But if you don’t plan on publishing this, it can really be whatever you want.</p><pre>Define value for property &#39;artifactId&#39;: project-name</pre><p>You can set the artifactId to your project name. I will be using VsCodeJavaUnitTests.</p><pre>Define value for property &#39;version&#39; 1.0-SNAPSHOT: :</pre><p>For your version, you can just select the default value by hitting enter.</p><pre>Define value for property &#39;package&#39; com.karlrombauts.VsCodeJavaUnitTests: :</pre><p>It will suggest a package name based on the group id you entered earlier. Again you can select the default by hitting enter.</p><p>Finally, it will ask you to confirm by typing <strong>Y</strong>.</p><p><strong>Great! </strong>Your maven project is setup :)</p><p>Now if you navigate to the destination folder you chose in the previous step, you will see you new project. You can now open this in VS code and we’ll get started with the next step.</p><h3><strong>Step 3: Correct Folder Structure</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*L5OcDSAkj9tZqqrDqQKs_A.png" /><figcaption>Your folder structure will be a bit different depending on the package name you gave in the previous step.</figcaption></figure><p>There are two main things that are important here:</p><ol><li>your project has a <strong>main</strong> folder and a <strong>test</strong> in the <strong>src </strong>folder</li><li>Inside both these folders you should have the same folder structure.</li></ol><pre>$ tree</pre><pre>.<br>├── pom.xml<br>└── src<br>    ├── main<br>    │   └── java<br>    │       └── com<br>    │           └── karlrombauts<br>    │               └── VsCodeJavaUnitTests<br>    │                   └── App.java<br>    └── test<br>        └── java<br>            └── com<br>                └── karlrombauts<br>                    └── VsCodeJavaUnitTests<br>                        └── AppTest.java</pre><p>You will also see that in the main folder structure you have a file called <strong>App.java</strong>, and in the test folder structure you have a file called <strong>AppTest.java</strong>. This is also important. Maven will automatically look for files with the *Test.java suffix when running tests. So a good convention to stick to is naming your test files [ClassName]Test.java.</p><p>Now, as you can see, my folder structure is missing the .classpath and .project files as well as a /target folder. You might already have these files, in which case just skip to the next step :)</p><p>This might be for two reasons; either VS Code is hiding these files for you, or they have not been generated automatically.</p><p>Lets first make sure they are not being hidden. Open your settings UI and search for <strong>Files: Exclude</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wq54R5qgMAB9ry0ChKS3yQ.png" /></figure><p>If you see mention of .classpath, .project or target/ just remove them from the list by clicking on the x on the right.</p><p>If they are still not showing up in the explorer reload the window. To do this press ctrl/cmd + shift + p to bring up the command palette and type <strong>reload window</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Uot_pMOzd_xL_omXSUmHw.png" /></figure><p>This will prompt VS to regenerate your java files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*2Q7HtKZvIbkYh0oK7UtHAA.png" /></figure><p><strong>Great</strong>, Now that we are set up, let’s move on!</p><h4>Note: If you have an existing project</h4><p>You can simply put all the files and folders of your existing project into a similar folder structure. Make sure that you create the same folder structure for your test folder. You will also have to update some of your package names in your java files.</p><h3>Step 4: Upgrade to JUnit5</h3><p>Open up your pom.xml file and in the &lt;dependencies&gt; section and replace</p><p>This:</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;junit&lt;/groupId&gt;<br>    &lt;artifactId&gt;junit&lt;/artifactId&gt;<br>    &lt;version&gt;4.11&lt;/version&gt;<br>    &lt;scope&gt;test&lt;/scope&gt;<br>&lt;/dependency&gt;</pre><p>With this:</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;<br>    &lt;artifactId&gt;junit-jupiter-api&lt;/artifactId&gt;<br>    &lt;version&gt;5.4.2&lt;/version&gt;<br>    &lt;scope&gt;test&lt;/scope&gt;<br>&lt;/dependency&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;<br>    &lt;artifactId&gt;junit-jupiter-engine&lt;/artifactId&gt;<br>    &lt;version&gt;5.4.2&lt;/version&gt;<br>    &lt;scope&gt;test&lt;/scope&gt;<br>&lt;/dependency&gt;</pre><p>If this is your first time dealing with a pom.xml file fear not, it is not as scary as it looks. The dependencies section is just telling Maven what you want to install. In this vase we want junit-jupiter-api version 5.4.2 and junit-jupiter-engine version 5.4.2. You will notice that each dependency has a groupId, artifactId and version. Just like we set up for our project. Each dependency also has a scope. You can read more about scope from this great Stack Overflow answer: <a href="https://stackoverflow.com/a/29230903">https://stackoverflow.com/a/29230903</a></p><p>After editing your pom.xml file, you should be prompted with this message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XmhSVBJ-ILYPCs3I_yzc7A.png" /></figure><p>You can either choose <strong>Now</strong> or <strong>Always,</strong> and it will go ahead and update your classpath configuration. <strong>Now</strong> will only update your configuration this time, while <strong>Always </strong>will automatically update the configuration each time you modify the pom.xml file in the future.</p><p>Finally, change the import statements in AppTest.java to the new JUnit5:</p><pre>import static org.junit.jupiter.api.Assertions.assertTrue;</pre><pre>import org.junit.jupiter.api.Test;</pre><p><strong>Sweet</strong>, JUnit5 is now installed. Let’s keep going :)</p><h3>Step 5: Write some tests</h3><p>This will be very project specific, so I will just do a very simple demo. This is by no means meant to be a unit testing tutorial, just how to set unit tests up in VS Code.</p><p><strong>BankAccount.java<br></strong>This is a VERY basic bank account class inside the <strong>main</strong> folder structure.</p><pre>package com.karlrombauts.VsCodeJavaUnitTests;</pre><pre>public class BankAccount {<br>    private int balance = 0;</pre><pre>    public BankAccount(int startingBalance) {<br>        this.balance = startingBalance;<br>    }</pre><pre>    public boolean withdraw(int amount) {<br>        if(balance &gt;= amount) {<br>            balance -= amount;<br>            return true;<br>        }<br>        return false;<br>    }</pre><pre>    public int deposit(int amount) {<br>        balance += amount;<br>        return balance;<br>    }</pre><pre>    public int getBalance() {<br>        return balance;<br>    }<br>}</pre><p><strong>BankAccountTest.java<br></strong>This is included in the <strong>test</strong> folder structure. In this file we will write all our unit tests. Lets write a very simple one for now.</p><pre>package com.karlrombauts.VsCodeJavaUnitTests;</pre><pre>import static org.junit.jupiter.api.Assertions.assertTrue;</pre><pre>import org.junit.jupiter.api.Test;</pre><pre>public class BankAccountTest {<br>    @Test<br>    public void withdraw_returnsTrue_ifEnoughFunds() {<br>        BankAccount account = new BankAccount(500);<br>        assertTrue(account.withdraw(400));<br>    }<br>}</pre><p>This test will check if you can withdraw 400 from an account that has a balance of 500. Which should return true.</p><p>Now thanks to our handy dandy <a href="https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test">Java Test Runner</a> we can run these tests without the need of the command line.</p><p>You can simply click on the Run Test and Debug Test shortcuts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tL-izf4n4KbZmv1-c1K4-g.png" /></figure><p>Or in the test explorer, you can view all your tests and run them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ZzzxVnoAMD96wc7GcYQsQ.png" /></figure><p>Cool, so let’s give our tests a whirl to make sure everything passes and let’s move on to the next step.</p><h4>Note: If you can’t see your tests in the Test Explorer and the shortcut are not showing up…</h4><p>This was an issue that I came across when I was setting this up. Firstly check that you have the right folder structure as described in the previous steps. By default VS Code will be looking for your tests in src/test/java/...</p><p>Then go check out .classpath and make sure it contains:</p><pre>&lt;classpathentry kind=&quot;src&quot; path=&quot;src/test/java&quot; output=&quot;build/classes/test&quot;&gt;<br>    &lt;attributes&gt;<br>        &lt;attribute name=&quot;test&quot; value=&quot;true&quot; /&gt;<br>    &lt;/attributes&gt;<br>&lt;/classpathentry&gt;</pre><p>For more on this issue: <a href="https://github.com/Microsoft/vscode-java-test/issues/470">https://github.com/Microsoft/vscode-java-test/issues/470</a></p><h3>Step 6: Code Coverage!</h3><p>Finally, we are up to the step that kick started all of this. We have our tests running. Now it would be nice to see how much of our code our tests are covering. Luckily this is “relatively” easy to set up. I put relatively in quotes because I spent 4 hours trying to get this to work, but I will help guide you so that you don’t make the same mistakes that I did.</p><p>We need to install some maven plugins. Crack open your pom.xml file again and add the following between the &lt;plugins&gt;...&lt;/plugins&gt; tags.</p><pre>&lt;plugin&gt;<br>    &lt;groupId&gt;org.jacoco&lt;/groupId&gt;<br>    &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;<br>    &lt;version&gt;0.8.4&lt;/version&gt;<br>    &lt;executions&gt;<br>        &lt;execution&gt;<br>            &lt;goals&gt;<br>                &lt;goal&gt;prepare-agent&lt;/goal&gt;<br>            &lt;/goals&gt;<br>        &lt;/execution&gt;<br>        &lt;execution&gt;<br>            &lt;id&gt;report&lt;/id&gt;<br>            &lt;phase&gt;prepare-package&lt;/phase&gt;<br>            &lt;goals&gt;<br>                &lt;goal&gt;report&lt;/goal&gt;<br>            &lt;/goals&gt;<br>        &lt;/execution&gt;<br>    &lt;/executions&gt;<br>&lt;/plugin&gt;<br></pre><p>JaCoCo (Java Code Coverage) is a plugin that will generate a report of your code coverage.</p><p>Now ready for some magic? Run this in your terminal:</p><pre>mvn jacoco:prepare-agent test install jacoco:report</pre><p>If all goes well (troubleshooting tips down below), you will now have a new file <strong>target/site/jacoco/index.html </strong>This is the code coverage report of your tests. You can open this in your preferred web browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v8u048C8gPU51yztSa1cCA.png" /></figure><p>And just like that, you have a very detailed report of your code coverage. BUT we can do better still.</p><p>If you have installed <a href="https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters">Coverage Gutters</a>, in your status bar at the bottom left you will see something that says Watch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*RbXQ_CIkc5N0Hps-9S5HLA.png" /></figure><p>Click on that to turn watch on. And then go check out the class you wrote tests for (in my case BankAccount.java)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*gCM-mhDa89fRu9LEh-cGeA.png" /></figure><p>Green bars indicate that that code has been reached by your tests. <br>Orange bars indicate a missed conditional check.<br>Red bars indicate code that was not reached by your tests.</p><p>This is helpful because this shows us that we have tested the case where the withdraw method returns true, but we haven’t tested the case where it returns false.</p><h4>Note: If you ran into any errors…</h4><p>First, make sure there are no errors in your code. Second make sure you that you upgrade both maven-surefire-plugin, and jacoco-maven-plugin to their latest versions. I kept getting errors when trying to set this up and ended up being an issue with old versions.</p><h3>Step 7: Update your tests</h3><p>I’ve added these two tests to the BankAccountTest.java file.</p><pre>@Test<br>public void withdraw_returnsTrue_ifWithdrawingAllFunds() {<br>    BankAccount account = new BankAccount(500);<br>    assertTrue(account.withdraw(500));<br>}</pre><pre>@Test<br>public void withdraw_returnsFalse_ifNotEnoughFunds() {<br>    BankAccount account = new BankAccount(500);<br>    assertFalse(account.withdraw(600));<br>}</pre><p>Now lets run the command again:</p><pre>mvn jacoco:prepare-agent test install jacoco:report</pre><p>And just like that out code coverage gutters are updated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*45DessT8Zz3dpX1zHJHv1Q.png" /></figure><h3>You’re done!</h3><p>Great job! If you’ve never used maven before, then that’s even better! I hope this article helped you and happy testing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3dc75579122f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>