Looking for good testing helpers

blov · · 668 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>My libraries do a lot on the file system, so I want to make sure that it&#39;s done right. To do so I basically keep a &#34;good&#34; filesystem tree and create an exactly the same side-by-side during tests. Are there any libraries doing the following:</p> <ol> <li>Fancy printing of structs and maps (tree-like representation);</li> <li>Comparing structs and maps, corresponding diffs;</li> <li>Comparing files on the file system;</li> <li>Comparing directories (recursively) on the file system;</li> <li>Fancy diffs on mismatched files/directories.</li> </ol> <p>Cheers</p> <hr/>**评论:**<br/><br/>jmank88: <pre><p>I&#39;ve used <a href="https://github.com/kr/pretty" rel="nofollow">https://github.com/kr/pretty</a> before for pretty printing structs and diffs.</p></pre>tucnak: <pre><p>Looks decent, still fails on printing big structs with branchy structure: no indentation.</p></pre>jmank88: <pre><p>Doesn&#39;t Formatter provide line breaks and tabs? </p></pre>jeffrallen: <pre><p>The best unit tests are so self-contained that they don&#39;t touch outside stuff, only their own RAM. Since you are doing filesystem operations, your first step should be to switch to Afero for your FS ops.</p> <p><a href="https://blog.gopheracademy.com/advent-2015/afero-a-universal-filesystem-library/" rel="nofollow">https://blog.gopheracademy.com/advent-2015/afero-a-universal-filesystem-library/</a></p></pre>tucnak: <pre><blockquote> <p>The best unit tests are so self-contained that they don&#39;t touch outside stuff, only their own RAM.</p> </blockquote> <p>Who said that? Using a filesystem for filesystem tests sounds way more reasonable to me.</p></pre>pievendor: <pre><p>Having file system unit tests in memory is the common pattern in a lot languages. There are two distinct advantages: </p> <p>1) cleanup is easy. 2) increasing your test concurrency is a lot safer so you can run your tests faster.</p> <p>It&#39;s the same principle that people discourage use of a real database in integration tests. It&#39;s slow and can cause test pollution if you&#39;re not careful or don&#39;t successfully tear down your suite.</p></pre>Manbeardo: <pre><p>For structure/map comparison, reflect.DeepEqual might be useful for you.</p></pre>tucnak: <pre><p>Well, it won&#39;t. It just tells whether structs equal or not. What you really wanna know for tests is what&#39;s the actual difference between the compared objects.</p></pre>lapingvino: <pre><p>you can still use it to check if you need to iterate more or not... reflect also provides everything to do that :)</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

668 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传