Live data from Hacker News

Ask HN: For a startup, when should I begin writing tests?

news.ycombinator.com

21–30 of 40 posts

Re: Ask HN: For a startup, when should I begin writing tests?

#21
post #16

Try to use tests to save time? A good compromise might be that if something doesn't work the first time you try it, you can write a test to make debugging faster. If it turns out you made a bad design decision down the road, you can always delete irrelevant tests and reapply the rule about testing to save time. Unfortunately, inexperience is going to make it take longer to write tests. That probably won't be what kil…

I'm curious - what kind of organisational issues relating to hiring new developers would be alleviated by having some tests? Are you referring to incoming developers being put off by the perception of a legacy codebase which is horrible to work with? Just curious!

I like to answer your question from my experience.

Your point is valid. Personally I would not join a company, as a software developer for software without tests. I would consider it if they hire me to lead their code improvement efforts, but even then no tests reflect engineering and business culture in that company (which is very hard to change). A big point I like to add is that new developers make more mistakes within a system they don't know. Having a good test suite gives young and experienced developers faster feedback about their assumptions of the system. Also unit tests act like an always up to date documentation which a developer can read to understand important assumptions about the parts of a system.

Re: Ask HN: For a startup, when should I begin writing tests?

#22
> I'm also afraid of digging an inescapable hole of untestable spaghetti code and tech debt.

How many engineers do you have and how fast are they likely to write code? It depends more on the product that you're building rather than the stack - if the tech is the product, spend more time on making sure it works as advertised. If the tech enables the product, spend less. Any competent engineer can pick up thousands of lines of technical debt/spaghetti code and spend a few afternoons swearing at it and figure out how to modify it. Technical debt is a problem, but more of a problem when you hit millions of lines, hundreds of engineers, and you need to be sure you can change stuff without breaking it.

Debt is useful - as long as you can take it on in a calculated way, don't stress about it too much. You might need to pivot and rewrite everything anyway, or at least have your fundamental assumptions changed in such a way that requires a partial rewrite. Tests won't help you much in those scenarios.

Re: Ask HN: For a startup, when should I begin writing tests?

#24
We wrote tests from day 1, but I have mixed opinions about the value of it. It certainly has helped at times, but it also adds a huge tax to everything.

Pros

* Established the proper culture from day one. If you end up being successful, this is extremely valuable. Culture is very, very hard to change.

* Eliminated a lot of bugs and regressions.

* Gave us confidence working in a regulated space.

Cons

* Adds a lot of time to initial development

* Product complexity doesn't really require testing in the early stages.

* Slows down ability to pivot

-----

If I were to do it again. I'd write fewer tests, but establish milestones for requiring changing/additions to be tested.

* My rule of thumb would be: If you can't easily test it in the UI, write a test. Or, if it's business critical, write a test.

* Verify authorization and authentication. It's very important.

* Test anything that makes/loses money (for example, Strip, Recurly, etc).

* Jest snapshots are quick and easy. Use them.

* Write tests for utility functions

Don't test:

* Database migrations

* UI interactions (unless critical). They take a lot of time to write and UI changes frequently.

* Vendor/3rd party API integrations beyond surface level. In my experience, quick implementations always involve a bunch of mocking/stubbing - making these types of tests less useful.

Re: Ask HN: For a startup, when should I begin writing tests?

#25
I stood up the product in 23 days, launched, will be 3 month young in couple of days. We have test cases written on our open to public python library, just one, nothing more than that. We purposefully asked a outsider, a freelancer, to write test cases for us looking in to the API documentation available on the website. This way we validated our documentation as well as the python library.

Re: Ask HN: For a startup, when should I begin writing tests?

#26
Working inwards from the edges of your product is a quick strategy that could provide immediate business value (compared to working from the bottom up watching metrics like coverage) and that means end-to-end testing.

Testing the product with end-to-end tests will stop you from shipping a completely broken product to your customer, where the most damage can occur. Add the test script at the end of the build and alert to a dashboard. “Alert” can mean email, and “dashboard” can mean “PC showing inbox for testalerts@mycompany”. You can get that running immediately. Alerts won’t tell you what broke of course, though you can use version control and bisecting to isolate breakages to commits, which is almost as good.

When you find bugs, then each bug is an opportunity to put some scaffolding around smaller subsystems as smaller tests to show the actual bug, as well as the fact that the bug has been fixed. Avoid committing the test without committing the fix. It’s a bad habit. You can show how the test used to fail in your commit message.

You’ll get an idea as to what are the most problematic pieces of your app. If one part is much less reliable than the others, then you can select that subsystem for verification with bottom up unit tests. Don’t spend too much time on each one though — it’s highly likely that in exercising your APIs through unit testing, you’re going to see ways in which they need to be refactored to make more sense and, importantly, become more reliable.

Re: Ask HN: For a startup, when should I begin writing tests?

#27
> I'm also afraid of digging an inescapable hole of untestable spaghetti code and tech debt.

if you are worried about tech debt you should watch "The art of destroying software". It will be hard to understand at first.

Here is TL;DR. Writing small services that will take only one week of work to rewrite. That way you can burn your services and recreate when you truly understand your domain.

Recently I worked on a REST API using go. I think the go package system has good support for writing small and independent packages. Just make sure your microservices are micro.

You can do the same for your React Codebase.

Re: Ask HN: For a startup, when should I begin writing tests?

#28
I would highly, highly recommend tests. The problem with not writing tests is that you think it will save you time, but instead, it will end up slowing your velocity greatly as your codebase grows and it becomes harder to discover what specific change broke feature X.

You don’t have to write thousands of unit tests. But you should absolutely have a basic test suite with integration tests that give you confidence in a new release. And it will make it easier to hire developers in the future.

A good test suite doesn’t slow you down at all, in fact, it speeds you up by helping you identify problems rapidly so you can fix code before it becomes a real problem.

Re: Ask HN: For a startup, when should I begin writing tests?

#30
I was in the same boat as you a year ago (solo developer building reviewnb.com). I wrote API tests for the backend (assert API x with y input returns z) and completely forgo any unit tests. This has given me 80% benefit with 20% effort.

I wrote these tests after launching the product publicly and just before support requests / bug fixing period started with the simple aim of avoiding regressions as I work through the improvements.

If I were to give general suggestions on the topic,

- In most cases having high level sanity tests is low effort high value decision.

- To write tests or not shouldn't be a binary decision. E.g. If you think a specific aspect is going to need refinement work then tests for those modules can help you immensely.

- Going for high % coverage very early on for the sake of mental satisfaction or bragging rights is usually not a good time investment

My only regret is not having any automated tests for frontend. Investing in some basic selenium tests after launch would have been worth it.

Post reply on HN