TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A survey of testing techniques we've found useful

98 pointsby lukes386about 5 years ago

6 comments

joshvmabout 5 years ago
One thing that is rarely discussed (I think?) is how to test things which don&#x27;t have a correct answer. It&#x27;s not just &quot;refactor until you can test&quot; it&#x27;s output that may be subjective. For example, suppose you write some code to do some image processing like a stereo matcher. How do you check your code works? Usually you have some ground truth which you can compare, but it&#x27;s difficult because you&#x27;ll never get 100% accuracy. At best you can declare a baseline, eg that your algo should be say 90% accurate (if you implemented it properly based on literature results) and if you don&#x27;t get that, then error. In that case you can use a numerical metric, but other applications you might care about the result being aesthetically pleasing (eg a video ISP where you do colour correction on the stream coming from a low level camera).<p>Or hardware where the advice is usually to mock the device under test. But if you don&#x27;t own the hardware the most you can do is try and emulate it, and maybe check that your simulated state machine works. In my experience its easier to run with hardware connected and just skip those tests otherwise. There are also extremely subtle bugs that can crop up with hardware interfaces like needing to insert delays into code (eg when sending serial) that will otherwise fail in the real world.<p>OpenCV has some interesting approaches to this, for example testing storing a video in a certain format, inserting a frame with a known shape (like a circle), then reading back the video and checking that the shape can be detected.
评论 #22841958 未加载
评论 #22841995 未加载
评论 #22843377 未加载
评论 #22842030 未加载
Lichtsoabout 5 years ago
I think this is a fairly good summary of the most important testing styles and where &#x2F; when to (not) use them.<p>One more category of tests I would add are meta tests (like mutation tests). These are tests which test the tests, seeing if they would actually catch any errors &#x2F; bugs or just report everything to be alright always.
discreteeventabout 5 years ago
&quot;If something is difficult to unit test, refactor until it&#x27;s easy.&quot;<p>This is often a good idea but if you only need the flexibility to enable unit testing then it may make your system more complex than it needs to be. Only introduce indirection where it&#x27;s really needed. See also &quot;test induced design damage&quot; and &quot;write tests, not too many, mostly integration&quot;.
评论 #22841697 未加载
epdlxjmonadabout 5 years ago
When writing code, we often think &quot;according to the design of our system, this condition must be true at this point of execution.” Examples are:<p>1. The argument x must not be 0.<p>2. The variable x must smaller than the variable y.<p>3. The list foo must be non-empty.<p>4. The variable x should have value &#x27;Success&#x27; if it had value &#x27;Try&#x27; in the beginning of the function call.<p>These &#x27;invariants&#x27;, or assertions, can be extremely useful for testing the correctness of the code. Put simply, if an invariant is violated (during unit test, integration tests, or system tests), it indicates that either the design or the implementation is wrong. An article on testing methodology would be more appealing if it had some discussion on exploiting invariants&#x2F;assertions.
评论 #22841956 未加载
评论 #22842122 未加载
choegerabout 5 years ago
Very nice overview. I very much agree that all these techniques are very useful. But one thing still bothers me. How does one test with a notion of time? How do you test a cron or a calendar with alarm function?
评论 #22846791 未加载
RaoulPabout 5 years ago
I’m a complete newbie when it comes to writing tests. But I know that SQLite is tested to hell and back, and I believe Richard Hipp (the creator) has said he spends more time and lines of code on the testing suite, than on the SQLite code itself. I hope he shares some of his insights some day.
评论 #22841626 未加载