<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Steven Kaufman</title>
    <description>The latest articles on Forem by Steven Kaufman (@stevekaufman).</description>
    <link>https://forem.com/stevekaufman</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F381233%2Fd3fc1e09-7c2b-415a-b142-c4c2fe79ebf2.jpg</url>
      <title>Forem: Steven Kaufman</title>
      <link>https://forem.com/stevekaufman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/stevekaufman"/>
    <language>en</language>
    <item>
      <title>TDD Practicality</title>
      <dc:creator>Steven Kaufman</dc:creator>
      <pubDate>Thu, 22 Apr 2021 05:39:22 +0000</pubDate>
      <link>https://forem.com/stevekaufman/tdd-practicality-46mo</link>
      <guid>https://forem.com/stevekaufman/tdd-practicality-46mo</guid>
      <description>&lt;h3&gt;
  
  
  Background
&lt;/h3&gt;

&lt;p&gt;As a young person getting into programming, it's hard not to notice the wildly varying cultural perspectives around the industry. &lt;br&gt;
From just watching YouTube tutorials, I think I was completely oblivious to the very existence of unit testing for at least a full year after learning the fundamentals of Javascript.&lt;/p&gt;

&lt;p&gt;Shortly after, however, I stumbled upon Robert C. Martin (Uncle Bob)'s talks on YouTube. &lt;br&gt;
If you haven't already seen his six publicly available hour-and-a-half long talks, I highly recommend watching ALL of them. &lt;br&gt;
I've personally rewatched and listened to them like podcasts in the car at least three times over. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtube.com/playlist?list=PLmmYSbUCWJ4x1GO839azG_BBw8rkh-zOj"&gt;Youtube: Clean Code - Uncle Bob&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Uncle Bob and TDD
&lt;/h3&gt;

&lt;p&gt;To summarize, he's one of the authors of the Agile Manifesto, a 50+ year software professional, and an extreme advocate for Test Driven Development.&lt;/p&gt;

&lt;p&gt;This advocacy for TDD sets him apart from even some of the other people who worked on the Agile Manifesto (which was designed to be a great compromise between wildly different programming philosophies).&lt;/p&gt;




&lt;h3&gt;
  
  
  My Question
&lt;/h3&gt;

&lt;p&gt;After playing around with TDD in personal projects, I can see its value, and I'm inclined to believe what Uncle Bob says. However, I want to be careful and make sure that I'm not blindly indoctrinating myself into some idealistic nonsense before I have much in the way of real world experience.&lt;/p&gt;

&lt;p&gt;I've seen the debates against TDD online, and Uncle Bob himself warns against trying to adopt things like TDD and Agile too quickly, as they're intended to be skills and disciplines that one has to practice to become effective at.&lt;/p&gt;

&lt;p&gt;My question is simply this, if anyone would like to share their opinion:&lt;/p&gt;

&lt;h3&gt;
  
  
  Why might TDD ever be a bad idea?
&lt;/h3&gt;

&lt;p&gt;or:&lt;/p&gt;

&lt;h3&gt;
  
  
  Why is TDD always a good idea?
&lt;/h3&gt;

</description>
      <category>tdd</category>
      <category>programming</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Expectate: A Go Testing Utility</title>
      <dc:creator>Steven Kaufman</dc:creator>
      <pubDate>Tue, 22 Dec 2020 07:34:29 +0000</pubDate>
      <link>https://forem.com/stevekaufman/expectate-a-go-testing-utility-5bp8</link>
      <guid>https://forem.com/stevekaufman/expectate-a-go-testing-utility-5bp8</guid>
      <description>&lt;p&gt;Do you love the simplicity of Go testing but hate writing if statements constantly?&lt;/p&gt;

&lt;p&gt;Do you like the 'expect' style syntax of testing libraries like &lt;strong&gt;jest&lt;/strong&gt; in JavaScript but don't care for Gomega?&lt;/p&gt;

&lt;p&gt;The answer:&lt;/p&gt;

&lt;h3&gt;
  
  
  Expectate
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/gomagedon/expectate"&gt;github.com/gomagedon/expectate&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is Expectate better than Gomega?
&lt;/h2&gt;




&lt;p&gt;Well, that's a matter of opinion. The main differences are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Expectate is simpler&lt;/li&gt;
&lt;li&gt;The syntax is a little different (closer to jest)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How is it simpler?
&lt;/h2&gt;




&lt;p&gt;If you've ever used Gomega (the Ginkgo assertion tool)...&lt;/p&gt;

&lt;p&gt;You wouldn't describe it as simple. It does a lot. Like a lot a lot. There are a lot of ways to write the same thing. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;DoSomethingSimple&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;Ω&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ShouldNot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HaveOccurred&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is the same as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;Ω&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DoSomethingSimple&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Should&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Succeed&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's not to mention the Expect syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DoSomethingSimple&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;To&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Succeed&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And those are just the different ways to assert that an error is nil!&lt;/p&gt;

&lt;h3&gt;
  
  
  The Expectate Way:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;DoSomethingSimple&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NotToBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it.&lt;br&gt;
No alternative syntax.&lt;/p&gt;

&lt;p&gt;In fact, Expectate has only 4 methods!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ToBe()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ToEqual()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NotToBe()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NotToEqual()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;ToBe()&lt;/code&gt; checks for simple equality, i.e. &lt;code&gt;var1 == var2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ToEqual()&lt;/code&gt; checks for deep equality using &lt;a href="//github.com/google/go-cmp"&gt;google/go-cmp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;NotToBe()&lt;/code&gt; and &lt;code&gt;NotToEqual()&lt;/code&gt; check for the opposite cases just like you would expect! (pun intended)&lt;/p&gt;
&lt;h2&gt;
  
  
  That's all it does?
&lt;/h2&gt;



&lt;p&gt;Yeah. So what?&lt;/p&gt;

&lt;p&gt;It's all syntactic sugar. The whole point is to turn a three-line &lt;em&gt;if&lt;/em&gt; statement into one line that looks nice and pretty. Gomega doesn't &lt;em&gt;actually&lt;/em&gt; provide much more functionality, just more ways to write the same thing.&lt;/p&gt;

&lt;p&gt;Expectate is real nice and lightweight 😎&lt;/p&gt;

&lt;p&gt;If I download the latest version of Gomega from GitHub, guess how big the zip file is?&lt;/p&gt;
&lt;h3&gt;
  
  
  Gomega size:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;gomega-1.10.4.zip: &lt;strong&gt;163K&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Compared to Expectate:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;expectate-1.0.0.zip: &lt;strong&gt;7K&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;



&lt;p&gt;Not to mention that all the production code for Expectate is in a single file, and 80% of that 7K is probably the tests.&lt;/p&gt;
&lt;h2&gt;
  
  
  So this is just another stupid testing library that doesn't do much?
&lt;/h2&gt;



&lt;p&gt;Right again.&lt;/p&gt;
&lt;h3&gt;
  
  
  Don't use it for everything!
&lt;/h3&gt;

&lt;p&gt;If you want a more descriptive error message than &lt;code&gt;foo is not bar&lt;/code&gt;, just use &lt;code&gt;testing.T&lt;/code&gt; like normal!!&lt;/p&gt;
&lt;h2&gt;
  
  
  A Note On Compatibility
&lt;/h2&gt;



&lt;p&gt;Expectate doesn't &lt;em&gt;have&lt;/em&gt; to use testing.T (although you really should)!&lt;/p&gt;

&lt;p&gt;Typically you would write an Expectate test like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;TestFooIsBar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;testing&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;expect&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;expectate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"foo"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ToBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"bar"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-------- FAIL: TestFooIsBar (0.00s)
    expect.go:34: foo is not bar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;The above example uses testing.T (as our lord and savior Rob Pike intended)&lt;br&gt;
But you can use any object that satisfies the &lt;code&gt;Fataler&lt;/code&gt; interface!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Fataler&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;Fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="k"&gt;interface&lt;/span&gt;&lt;span class="p"&gt;{})&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So anyway check it out! It's my very new project, so please give lots of feedback, positive or negative! Open all the issues!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/gomagedon/expectate"&gt;github.com/gomagedon/expectate&lt;/a&gt;&lt;/p&gt;

</description>
      <category>testing</category>
      <category>go</category>
    </item>
  </channel>
</rss>
