<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Testing on Gopher Coding</title><link>https://gophercoding.com/tags/testing/</link><description>Recent content in Testing on Gopher Coding</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Fri, 27 Sep 2024 19:47:11 +0100</lastBuildDate><atom:link href="https://gophercoding.com/tags/testing/index.xml" rel="self" type="application/rss+xml"/><item><title>Writing Tests in Go (a Beginners Guide)</title><link>https://gophercoding.com/how-to-write-a-basic-test/</link><pubDate>Sat, 02 Mar 2024 05:00:00 +0000</pubDate><guid>https://gophercoding.com/how-to-write-a-basic-test/</guid><description>&lt;p>There a many benefits to testing your code in general, which we won&amp;rsquo;t go into detail on (but if you&amp;rsquo;re interested, take a look &lt;a href="https://stackoverflow.com/questions/67299/is-unit-testing-worth-the-effort">here&lt;/a>) all we will say is the quote below.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;Imperfect tests, run frequently, are much better than perfect tests that are never written at all&amp;rdquo;. - Fowler&lt;/p>
&lt;/blockquote>
&lt;h2 id="first-test">First Test&lt;/h2>
&lt;p>We&amp;rsquo;ve created the most basic progam, to add two numbers together, below in &lt;code>main.go&lt;/code> which we&amp;rsquo;re going to write a test for. Tests in Go are found in &lt;strong>separate files&lt;/strong> to the code and are within &lt;code>*_test.go&lt;/code> - where * is the filename. So our test would be &lt;code>main_test.go&lt;/code> - but if your go file was &lt;code>address.go&lt;/code>, you&amp;rsquo;d create a &lt;code>address_test.go&lt;/code> and store them here.&lt;/p></description></item></channel></rss>