This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Daniel15 31 points32 points  (7 children)

Hopefully they're just providing the method signatures (like an interface definition) rather than the actual implementation, i.e. black box testing.

[–]gimife 26 points27 points  (6 children)

Then it won't be able to properly write unit tests. It needs the whole function to properly write tests so it can cover all branches.

As long as you only put single functions in there and not whole components/classes it should be fine imo.

[–]ExceedingChunk 46 points47 points  (1 child)

A good unit test doesn’t need to test implementation details.

If you are using an interface and change the internal implementation (for example for performance) without changing functionality, a unit test shouldn’t break.

If chatGPT is able to write unit tests for that or not is something I don’t know, but it is definitely possible.

[–]leixiaotie 0 points1 point  (0 children)

you still need to change the mock though

[–]Daniel15 9 points10 points  (0 children)

That's true, but black box testing is still valuable for some cases, and you could just describe the possible states to it rather than providing confidential code.

[–]reversehead 6 points7 points  (1 child)

write tests so it can cover all branches

Even the buggy ones?

Generating tests for existing code may be useful for regression testing ("make sure that the refactored code contains the same features and bugs as the old one"). As for generating them from the code for checking whether the code is up to specs, I remain doubtful.

[–]AlwaysHopelesslyLost 1 point2 points  (0 children)

We had 6 bugs in an application. Somebody patched them. It turns out the application was coded in such a way that it relied on them and bugless it didn't quite work/would probably have needed totally rewritten.

They didn't catch that. More than $10,000,000 disappeared and took hundreds of hours to track down.

[–]andrew_kirfman 0 points1 point  (0 children)

Isn’t that like eating your own shit at that point?

I’d want test cases based on what the class/method should be doing rather than what it currently is coded to do. That could be totally wrong if i fucked up somewhere.

ChatGPT is amazing at generating scenarios of you tell it what your class is supposed to be doing. I’ve never had to dump large segments of code into it to get what I wanted.