<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Simeon Visser (go)</title><link>http://simeonvisser.com/</link><description></description><language>en</language><lastBuildDate>Thu, 05 Jun 2014 02:47:36 GMT</lastBuildDate><generator>http://getnikola.com/</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>How to Test Package Main in Go</title><link>http://simeonvisser.com/posts/how-to-test-package-main-in-go.html</link><dc:creator>Simeon Visser</dc:creator><description>&lt;p&gt;There are a few things to get right when trying to test the main package in Go.
This is a result of package naming rules and where files need to be located. My
attempts from other testing frameworks (such as Python) led me to error messages
such as:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;cannot find package "mypackage" in any of: /first/path/ (from $GOROOT), /second/path/ (from $GOPATH)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;can't load package: package mypackage: found packages main (mypackage.go) and mypackage (mypackage_test.go) in /project/path&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;./mypackage_test.go:4: import "path/to/mypackage" while compiling that package (import cycle)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;However, it should be possible to resolve all these errors by following
this checklist:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;An executable package must have the name &lt;code&gt;main&lt;/code&gt; (so &lt;code&gt;package main&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;The name of the code file can be as desired, so &lt;code&gt;example.go&lt;/code&gt; in this example.&lt;/li&gt;
&lt;li&gt;The name of the test file should have &lt;code&gt;_test.go&lt;/code&gt; at the end, so &lt;code&gt;example_test.go&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The test file should be in the same directory as the code file.&lt;/li&gt;
&lt;li&gt;The package name of the test file must also be &lt;code&gt;package main&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;There is no need to import the code in the test file as everything is in the same package.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;You don't necessarily need to have these files in a subdirectory of your project; you can
have all files in the root directory of the project.&lt;/p&gt;</description><category>go</category><guid>http://simeonvisser.com/posts/how-to-test-package-main-in-go.html</guid><pubDate>Thu, 05 Jun 2014 00:00:00 GMT</pubDate></item></channel></rss>