← Home ← Back to /g/

Thread 106332783

29 posts 8 images /g/
Anonymous No.106332783 >>106332837 >>106332860 >>106334269
What the hell is a unit test?
Anonymous No.106332817 >>106333801 >>106336237 >>106336284
it's when you write hundreds of contrived tests to make sure one of your changes didn't break some core functionality of the program but really all it does is ensure retards will break your program in ways not covered by the unit tests, it's pointless makework
Anonymous No.106332837
>>106332783 (OP)
Code that goes into production should be covered by tests, usually producing testing code at a rate of 5:1 or more.

It means that your code should be isolated into units and tested that it behaves correctly.
Anonymous No.106332860
>>106332783 (OP)
A unit test is tue simplest thing. You write a function, then you write code which tests how your function works and what the results of running your function are given different inputs - that's a unit test.

Try all sorts of other tests: integration, functional... I still have no particular idea what those are and just really stick to writing unit tests only.
Anonymous No.106333253 >>106333277 >>106334978 >>106335202 >>106336189
>absolute unit test
Anonymous No.106333277
>>106333253
I'm gonna be sad if this image turns out to be aislop (100% sure it isn't, though).
Anonymous No.106333801 >>106333915 >>106336343
>>106332817
And when the client complains that 1/3 of their data is corrupt the devs say "Not my problem, all the unit tests are green. Must be a hardware error."
Don't ask me how I know.
Anonymous No.106333915 >>106336352
>>106333801
>data is corrupt
How can a unit test find corrupt data?
Anonymous No.106334269 >>106336269 >>106336364 >>106336364 >>106336364
>>106332783 (OP)
Any good resources for writing unit tests well? AI literally can't automate that. It produces something, but it's not working. I can instruct it to write unit tests for the app and it just spams tests to get like a few percent coverage and almost everything failing. Or is my code just this shite?
Anonymous No.106334978
>>106333253
oh lawd
Anonymous No.106335202
>>106333253
Anonymous No.106336189
>>106333253
Test PASSED
Anonymous No.106336237 >>106336373
>>106332817
If you work at a trash company like mine, they will just change your interfaces anyway and fuck it up.
Anonymous No.106336267
A unit test is a way to check if a small piece of code (called a "unit") works correctly. It's like a diagnostic tool for developers.
Imagine you're building a Lego castle. A unit test would be like checking if a single Lego brick fits together with others as expected. If it doesn't, you know there's a problem with that specific brick.
In coding, unit tests help catch errors early, ensure code quality, and make it easier to modify or extend the codebase. They're usually automated and run repeatedly to ensure the code keeps working as intended.
Anonymous No.106336269
>>106334269
I don't know what you mean. You can program more or less, right? Do the AI unit tests assume something that you actually want to be true? Like do you want your variables to be initialised to something specific? Do you want to throw an exception when some stuff happens? You have to know what you want to happen in edge cases first.
Anonymous No.106336284
>>106332817
>Setting bounds on how your code can break
Sounds pretty good, actually.
Anonymous No.106336326 >>106336395 >>106337856
A unit test is when you define f(x) = 1 for all x and then write g() which calls f(y) for a random number y = rand(s) which has to be tested in h() to check if rand(s) = m where m is some number a boomer pulled out of his ass in 1973 on his atari lynx workstation is the same on all cloud machines (someone elses PDP-11 behind a paywall) and so on to check if f(y) returns 1 and g() returns 0 instead of just inspecting the compiled assembly

They call it unit because 1 (one, a unit) retard is all you need to destroy rational logical paradigms
Anonymous No.106336343 >>106336360
>>106333801
There's a 99% chance you have been working with pajeets.
Anonymous No.106336352
>>106333915
>How can a unit test find corrupt data?
Erroneous output for starters.
Input errors.
Pretty easy.
Anonymous No.106336360 >>106336672
>>106336343
We had a British freelancer write some code for us and I wondered why the unit tests were all commented out.
>They didn't pass so I commented them out
Anonymous No.106336364 >>106336408 >>106337395
>>106334269
>>106334269
>>106334269
Bro wants AI to write everything in one go LMFAO.
Just ask it to do... single units. LOL!
>Or is my code just this shite?
I'mma presume yes. You gotta learn the basics before you use AI for this dude.
Anonymous No.106336373
>>106336237
The AI wrote those anyway. Just automate the new units. Not hard to API feed the units into an AI to generate tests. Script this then take a break for the next few weeks.
Anonymous No.106336395 >>106337765
>>106336326
Not good (in general) to use random inputs.
Your test would then pretty much have to solve the problem in the first place lol.
Anonymous No.106336408 >>106337395
>>106336364
It's not necessarily "trash" I suspect that he writes personal, one person projects and he just knows how a class will be used. As long as you're aware of that it's not really a problem, but potentially he's not.
Anonymous No.106336672
>>106336360
>British
Anonymous No.106337395 >>106337539
>>106336364
I honestly think I know the basics of programming. Probably even advanced concepts. I have no blockages when writing code, except when I have to spend time figuring out how I can code something of course. But it's hands down not optimal code.
I just assumed that if anything, the AI would excel at writing simple unit tests. Gave it a go and the results weren't good. Have never bothered with writing unit tests myself before, but going productive soon, so I want that for safety.

>>106336408
Yeah it's a personal app, one person project you got that right.
Anonymous No.106337539
>>106337395
Just design your tests to make sure the functions accept data in the correct way, and output expected results.
Target edge-cases.
AI should be able to do it for you, but you absolutely have to be able to verify it for yourself.
Anonymous No.106337765 >>106337856
>>106336395
>random
>input
anon...
Anonymous No.106337856
>>106337765
>>106336326
>for a random number y = rand(s)
>g() which calls f(y)
>unit test is when you define f(x)