Jump to content

Automated tests for code


usauae

Recommended Posts

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.

 

Link to comment
Share on other sites

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

  • Like 1
  • Haha 1
Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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. 
 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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 

  • Haha 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...