usauae Posted February 24, 2023 Report Share Posted February 24, 2023 calling @dasari4kntr @ramudu and any other tech enthusiasts. I have an api endpoint that checks for a condition and does some logic. so we had a small block of code that was not working as intended. Maa manager looked at the code and asked why did we not have unit tests for that condition. And why are we checking for nulls in multiple places. Asking us to move that to a method. (Only 2 places lo vundi) So my question is 1. do you write integration tests that run every time you commit the code? 2. do you write unit tests that cover each and every possibility ? 3. Does code coverage really help with producing better code ? 4. Would you move code to its own method even if it is repeated once ? Yemi aina ante yedo oka book refer chesi chadavandi ani sava dobbutundi maa manager. Quote Link to comment Share on other sites More sharing options...
ramudu Posted February 24, 2023 Report Share Posted February 24, 2023 4 minutes ago, usauae said: calling @dasari4kntr @ramudu and any other tech enthusiasts. I have an api endpoint that checks for a condition and does some logic. so we had a small block of code that was not working as intended. Maa manager looked at the code and asked why did we not have unit tests for that condition. And why are we checking for nulls in multiple places. Asking us to move that to a method. (Only 2 places lo vundi) So my question is 1. do you write integration tests that run every time you commit the code? 2. do you write unit tests that cover each and every possibility ? 3. Does code coverage really help with producing better code ? 4. Would you move code to its own method even if it is repeated once ? Yemi aina ante yedo oka book refer chesi chadavandi ani sava dobbutundi maa manager. 1. do you write integration tests that run every time you commit the code? - unit test is mandatory but integration testing is hard , we use mocking for integration test during commits 2. do you write unit tests that cover each and every possibility ? - as much as possible , I know 100% coverage is dream but it is too hard 3. Does code coverage really help with producing better code ? - coverage defiantly helps , it eventually helps to find dead code also 4. Would you move code to its own method even if it is repeated once ? SOLID principles lo S , single responsibility , let your method do that single responsibility irrespective of any number of times that method being called , lets say you are saving user and sending email , better separate saving and sending emails to separate methods , let them do the single responsibility , that is easy for debugging , unit testing as well 1 1 Quote Link to comment Share on other sites More sharing options...
ramudu Posted February 24, 2023 Report Share Posted February 24, 2023 Yemi aina ante yedo oka book refer chesi chadavandi ani sava dobbutundi maa manager. --- emi book bro , read clean code from uncle bob if you are junior Quote Link to comment Share on other sites More sharing options...
Popular Post dasari4kntr Posted February 24, 2023 Popular Post Report Share Posted February 24, 2023 16 minutes ago, usauae said: calling @dasari4kntr @ramudu and any other tech enthusiasts. I have an api endpoint that checks for a condition and does some logic. so we had a small block of code that was not working as intended. Maa manager looked at the code and asked why did we not have unit tests for that condition. And why are we checking for nulls in multiple places. Asking us to move that to a method. (Only 2 places lo vundi) So my question is 1. do you write integration tests that run every time you commit the code? 2. do you write unit tests that cover each and every possibility ? 3. Does code coverage really help with producing better code ? 4. Would you move code to its own method even if it is repeated once ? Yemi aina ante yedo oka book refer chesi chadavandi ani sava dobbutundi maa manager. For Second Question: YES..initially that is painful..but once you used to it...its the best approach For Third Question and Fourth Question: coverage means, your code is covered with unit tests or not..? if your code is covered with unit tests obviously your code is much better.. unit tests secretly makes you learn SOLID principles... if you want to implement Unit test you have to learn dependency injection..etc so obviously your code will be loosely coupled. For First question: this is the git flow model, most of the organizations follow this model..with minimal changes... at feature level, you need to run build and unit tests at develop level, you need to run the build, tests, coverage, integration..etc at release level, you need to run build, tests, coverage, integration, vulnerability scans, security code scans..etc 1 2 Quote Link to comment Share on other sites More sharing options...
csrcsr Posted February 24, 2023 Report Share Posted February 24, 2023 24 minutes ago, usauae said: calling @dasari4kntr @ramudu and any other tech enthusiasts. I have an api endpoint that checks for a condition and does some logic. so we had a small block of code that was not working as intended. Maa manager looked at the code and asked why did we not have unit tests for that condition. And why are we checking for nulls in multiple places. Asking us to move that to a method. (Only 2 places lo vundi) So my question is 1. do you write integration tests that run every time you commit the code? 2. do you write unit tests that cover each and every possibility ? 3. Does code coverage really help with producing better code ? 4. Would you move code to its own method even if it is repeated once ? Yemi aina ante yedo oka book refer chesi chadavandi ani sava dobbutundi maa manager. For very checkin during the build itself unit testing is done anna , we use jmockit at least 90% coverage lekapothe build fail Once code deploy is done all the integration tests are mandatory to.promote to stage , in our case we have some down streams from dev when they are not ready we wrote simulators to return standard response accordibg to specbut most of them fully integrated tests Jmockit easy anna if u are talking about Java Quote Link to comment Share on other sites More sharing options...
usauae Posted February 24, 2023 Author Report Share Posted February 24, 2023 So you recommend writhing unit tests with all possible combinations. But oka endpoint program cheyyali ante how much time do you take? For us the expectation is 1 day max. Aa one day lo unit tests kuda na ani skipping. Quote Link to comment Share on other sites More sharing options...
csrcsr Posted February 24, 2023 Report Share Posted February 24, 2023 Just now, usauae said: So you recommend writhing unit tests with all possible combinations. But oka endpoint program cheyyali ante how much time do you take? For us the expectation is 1 day max. Aa one day lo unit tests kuda na ani skipping. depends on logic anna if you are exposing a endpoint , but that endpoint has many integrayion points defienetly one day is not enough if you are just giving data from db with min logic may be one day , unit testing should be in dna , maa degara PR lo 10engi ispedtharu lekapothe they will not allow to merge Quote Link to comment Share on other sites More sharing options...
Vaampire Posted February 24, 2023 Report Share Posted February 24, 2023 Integration tests koncham kastam & time consuming. unit tests mathram pakka. Konni companies strick policy untadi code coverage 95+% undali ani. Unit tests are very helpful in blocking code changes which could potentially break. having smaller methods is always encouraged. Easy to understand and easy to maintain Quote Link to comment Share on other sites More sharing options...
Vaampire Posted February 24, 2023 Report Share Posted February 24, 2023 Ayina chargpt, bard kalam idhi. Method isthey avvey unit tests isthunnayi. Inka problem enti? Quote Link to comment Share on other sites More sharing options...
csrcsr Posted February 24, 2023 Report Share Posted February 24, 2023 Just now, Vaampire said: Ayina chargpt, bard kalam idhi. Method isthey avvey unit tests isthunnayi. Inka problem enti? anta easy kaadu le anna that is our method , code has to write tests to your functionality how will chat gpt help here malli you have to use standard frameworks what is there in legacy code chatr gpt will not help may be odd syntax etc 1 Quote Link to comment Share on other sites More sharing options...
usauae Posted February 24, 2023 Author Report Share Posted February 24, 2023 26 minutes ago, ramudu said: Yemi aina ante yedo oka book refer chesi chadavandi ani sava dobbutundi maa manager. --- emi book bro , read clean code from uncle bob if you are junior books ante kashtam bro. Unit tests ki udemy lo videos chusa but maa code ki vachhesariki lot of factors changed and trying to implement unit tests on existing code. So chiraku ga vundi. As for the book she recommended "Domain Driven Design - Tackling complexity in the heart of software" By Eric Evans Quote Link to comment Share on other sites More sharing options...
Vaampire Posted February 24, 2023 Report Share Posted February 24, 2023 4 minutes ago, csrcsr said: anta easy kaadu le anna that is our method , code has to write tests to your functionality how will chat gpt help here malli you have to use standard frameworks what is there in legacy code chatr gpt will not help may be odd syntax etc @k2s thatha mee chatgpt ni edo antunnadu Quote Link to comment Share on other sites More sharing options...
usauae Posted February 24, 2023 Author Report Share Posted February 24, 2023 31 minutes ago, ramudu said: 1. do you write integration tests that run every time you commit the code? - unit test is mandatory but integration testing is hard , we use mocking for integration test during commits 2. do you write unit tests that cover each and every possibility ? - as much as possible , I know 100% coverage is dream but it is too hard 3. Does code coverage really help with producing better code ? - coverage defiantly helps , it eventually helps to find dead code also 4. Would you move code to its own method even if it is repeated once ? SOLID principles lo S , single responsibility , let your method do that single responsibility irrespective of any number of times that method being called , lets say you are saving user and sending email , better separate saving and sending emails to separate methods , let them do the single responsibility , that is easy for debugging , unit testing as well so ex: 2 lines of code repeat aina we should consider moving it to a method ? Over engineering ani antaru yemo anukunna all these days. Quote Link to comment Share on other sites More sharing options...
ramudu Posted February 24, 2023 Report Share Posted February 24, 2023 Just now, usauae said: so ex: 2 lines of code repeat aina we should consider moving it to a method ? Over engineering ani antaru yemo anukunna all these days. mari aa level lo over engineering kadhu , a method should do single task , just single task Quote Link to comment Share on other sites More sharing options...
usauae Posted February 24, 2023 Author Report Share Posted February 24, 2023 15 minutes ago, csrcsr said: depends on logic anna if you are exposing a endpoint , but that endpoint has many integrayion points defienetly one day is not enough if you are just giving data from db with min logic may be one day , unit testing should be in dna , maa degara PR lo 10engi ispedtharu lekapothe they will not allow to merge meeru andaru 8 hrs work ante asalu distract avvakunda chestara bro ? manaki kavalsina data ki query rasukovali, model create cheyyali, map cheyyali(of course automapper yele) controller, service layer, repository layer classes create cheyyali. possible null and other checks cheyyali not complaining but I want to enjoy coding and don't feel like a burden. Adi yela alavatu chesukovala ani asking thats all Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.