96 points · by _cfl0 · 4y ago · 63 comments
I decided to build a tool that will enable you to: Change code -> look at failures.
No wait time, no explicit test running.
Under the hood:
- Runs the whole test suite and collects code coverage per test.
- For each auto file save, analyzes the changes on the tests.
- Runs changed tests in the background.
- Display results, the loop time from change to test results is approx 250ms.
Instead of:
code -> alt+tab -> arrow up -> rerun all the tests -> wait ... -> test results code -> alt+tab -> test results!
Check it out! <https://github.com/nabaz-io/nabaz>
InfiniTest - https://infinitest.github.io/ an dhttps://infinitest.github.io/doc/intellij#how-it-works
JUnit Max - https://web.archive.org/web/20090206151635/http://www.threer... partially surviving as https://junit.org/junit4/javadoc/4.12/org/junit/experimental...
Ruby has something similar:
autotest - https://github.com/grosser/autotest
I think it's a good idea, and i'm surprised it hasn't become a standard feature of IDEs and test runners.
The key innovation piece here is the speed that the extreme selectively enables you.
Nabaz selects a small subset of affected tests, reducing CPU usage, and more importantly improving speed drastically!
Regardless, running tests in the background to eliminate human delay is good. It would be nice if the (~test time)*(test change likelihood) of the tests were used to order tests based on fastest relevant feedback.
A code->test change likelihood map may also be used to reveal previously unexpected dependencies. Also ~test time could be difficult (see halting problem and windows time remaining estimates).
This is good work.
It doesn't need to rely on "test change likelihood" - if a code change is outside of the code coverage of the test, it doesn't affect the test.
This assertion questionable, the extent it is true it is language specific.
Here is a counterexample in Java:
// foo.java
public class Foo {
public static final int LENGTH = 10;
}
// bar.java
public class Bar {
public int getFooLength() {
return Foo.LENGTH;
}
}
Code coverage tools will not highlight Foo as being touched when Bar.getFooLength is invoked, even though a test asserting that getFooLength() is 10 will fail or succeed depending on Foo.LENGTH. The reason for this is that Foo.LENGTH is inlined in Bar. If you for example wanted to patch a new version of the value, you need to supply Bar.class to affect the change; patching Foo alone would do nothing.C and C++ likewise do not satisfy this requirement because macros.
Like, e.g. if I change a macro in a header file and press "rebuild" on the project, MSVC (or MSBuild driven by CMake) will figure out that the header was changed, chase down which translation units include it directly or transitively, and rebuild those, then link the output and... chase down everyone else who links to the output and relink them, etc.
I bet you could produce a counterexample that breaks this mechanism (C++ being what it is), but I don't expect to see it in an actual codebase.
If I would get a break from hn comments I could finish it today lol ;)
We’re thinking of adding watch mode in the coming months - running tests continuously in real-time. Sending you an email to exchange ideas.
P.S.- there might be few typos. It’s work in progress.
[1] https://www.youtube.com/watch?v=Nc-TlgeKBSE [2] https://github.com/crusherdev/crusher
For example, I run:
fd -e j2 -e py | entr -c python3 build.py
To rebuild a static site every time the build script[2] (py) or a Jinja2 template (j2) changes.[0]: https://github.com/eradman/entr
[1]: https://jvns.ca/blog/2020/06/28/entr/
[2]: https://gist.github.com/polyrand/3bed83897658806bd490e1d44df...
hypertest only runs the tests the were impacted by the changed code. Resulting is blazing fast performance.
I’d say it’s even fast than apples alt+tab animation most of the time.
This is not true though. Might depend on the test tooling used, but most of the ones I've used only run changed tests (either directly or through change detection via git, e.g. https://nx.dev/concepts/affected)
How many tests will your system run? That's the important question.
You can’t use it live, And also the analysis granularity is just way too wide compared to this.
with all due respect, this is also a solved problem with test watchers. unless you mean this is smart enough to not just run unit tests that are directly related to the file changed, but also understands code changes from the perspective of downstream dependencies?
This is more of a code watcher than a test watcher specifically.
[1]: https://github.com/bazelbuild/bazel-watcher [2]: https://facebook.github.io/watchman/
Bazel (and bazel watcher) really shines when you have lots of small packages.
I don’t quite get this proposition. If easily distracted, and wanting to stay focused, wouldn’t you rather want to run tests only on demand and not be interrupted by failing tests after changing just a line or two and still not finished with the rest of your changes.
I can see the benefits of a fast feedback loop. But not sure the pitch of keeping you focused is how i would see it work for me. YMMV.
Can you cache the coverage DB so this can be run in a CI pipeline?
2. How does it detect what tests need to be re-run when a given file changes?
2. The first run and every subsequent one collects code coverage which is saved in an sqlite db. Every file change is compared to the code coverage.
Although this approach isnt perfect, The idea here is being fast. I always rerun the entire suite just before committing the code.
As the author explained in another comment, it initially generates the code coverage for all tests. When code is changed, only the tests that cover that code are rerun.
So you can always rely on that background terminal for actual test failure reasons.
watch -n 1 run-test-tool
But I guess this depends on your test tool of choice not being too slow to boot.while [ 1 ]; do inotifywait .{c,h} t/.{c,h}; make && make check ; done
Though I understand the intent, I think it has the risk to run into a run-hack-run-hack programming style.
I'm currently reading Code Complete which advises against this practice. Instead, one should strive to write code that works from the start instead of hoping it to work eventually.
I use it as I would run tests through a terminal normally. Built this because I hate running tests.