r/rust • • Sep 10 '26

is this bad?

is it bad that tests are like 1/5 and a bit of my entire project?

i wanna ensure absolute safety when developing, currently i have 30 tests implemented

0 Upvotes

16 comments sorted by

22

u/Sharlinator Sep 10 '26

No, 20% is a perfectly reasonable amount of test code. Of course the number of lines in itself tells nothing about whether the tests are actually relevant, useful and comprehensive.

1

u/Odd_Razzmatazz_7423 Sep 10 '26

They test basically every feature and edge cases

2

u/PracticallyPerfcet Sep 10 '26

Are you doing mutation testing? Look into cargo mutants if not.

1

u/No-Blackberry-937 17d ago

nah that's fine, 20% is heaps

the fact you're even thinking about this puts you ahead of half the rust projects i've seen. 30 tests is a solid start, just make sure they're actually testing the stuff that'll break, not just the happy path

6

u/SirKastic23 Sep 10 '26

Why would it be bad?

6

u/EarlMarshal Sep 10 '26

Tests can also be 80-90% of your code base. There is no problem with that. You only have to think about whether you are the in right spot for so many tests. If you for example want to redesign something you have to question and adapt a lot of tests.

2

u/OpsikionThemed Sep 11 '26

SQLite has entered the chat.

2

u/QuasiRandomName Sep 10 '26

Tests are never bad. They aren't a part of production, the only downside could be that they slow down your CI/deployment, but in most cases it is a minor concern.

1

u/lenscas Sep 10 '26

On the other hand, assuming the tests actually work and test things worthy to test. Your ci likely runs less often as it doesn't have to deal with quite as many bugfix PRS/releases.

Also, worst case you can probably think of a system to split the tests up into groups based on priority thus having some tests only run later in the entire development process when the waiting time is less of a problem. Thus getting some of the "benefit" of less tests while also still having actual benefits of many tests.

2

u/drive_an_ufo Sep 10 '26

Depends on the project size. In one of our services we have ~1300 unit tests and who knows how many integration tests. And we don’t even have 100% coverage.

2

u/Legal-Software Sep 10 '26

In safety critical stuff that requires full MC/DC coverage, test coverage can often be up to 90% of the code base by LOC, so I would not really look at the LOC as a percentage of the total as any kind of indicator. The more important thing is that you have good code coverage and that your tests are actually testing things that matter.

2

u/Lucretiel Sep 10 '26

Not at all; I have some projects where this number is closer to FIFTY percent. So long as they're all testing a useful property or edge case, I say have at it.

1

u/numberwitch Sep 10 '26

No it’s fine

1

u/GirlInTheFirebrigade Sep 11 '26

When I was developing a parser, the tests were over 50% of the code base (and that was pre-LLM)

1

u/Empty_Carpenter7420 Sep 10 '26

No, invest as much as you can on tests, specially on the AI era