[{"data":1,"prerenderedAt":1101},["ShallowReactive",2],{"tag-tdd":3},[4],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":10,"date":11,"layout":12,"subtitle":13,"image":14,"optimized_image":14,"category":15,"tags":16,"author":20,"paginate":7,"body":21,"_type":1095,"_id":1096,"_source":1097,"_file":1098,"_stem":1099,"_extension":1100},"/posts/tdd-testing","posts",false,"","Test-Driven Development (TDD) in Java with JUnit and Mockito","Understanding Test-Driven Development (TDD) in Java using JUnit and Mockito with practical examples.","2024-01-15T11:00:00.000Z","post","Writing Better Code with Automated Testing","/assets/img/uploads/tdd-java.png","code",[15,17,18,19],"java","testing","tdd","jaimedearcos",{"type":22,"children":23,"toc":1088},"root",[24,36,43,48,68,73,79,88,93,98,317,325,330,335,610,616,621,832,837,1015,1020,1026,1031,1037,1042,1077,1082],{"type":25,"tag":26,"props":27,"children":28},"element","blockquote",{},[29],{"type":25,"tag":30,"props":31,"children":32},"p",{},[33],{"type":34,"value":35},"text","In modern software development, ensuring code quality and reliability is crucial. Many job interviews for Java developers assess knowledge of automated testing frameworks like JUnit and Mockito. Test-Driven Development (TDD) is a methodology that not only enhances code quality but is also a highly sought-after skill in the industry.",{"type":25,"tag":37,"props":38,"children":40},"h2",{"id":39},"what-is-tdd",[41],{"type":34,"value":42},"What is TDD?",{"type":25,"tag":30,"props":44,"children":45},{},[46],{"type":34,"value":47},"Test-Driven Development (TDD) is a software development methodology where tests are written before implementing functionality. It follows a repetitive cycle known as \"Red-Green-Refactor\":",{"type":25,"tag":49,"props":50,"children":51},"ul",{},[52,58,63],{"type":25,"tag":53,"props":54,"children":55},"li",{},[56],{"type":34,"value":57},"Red: Write a test that fails (since the functionality is not yet implemented).",{"type":25,"tag":53,"props":59,"children":60},{},[61],{"type":34,"value":62},"Green: Write the minimal code required to pass the test.",{"type":25,"tag":53,"props":64,"children":65},{},[66],{"type":34,"value":67},"Refactor: Improve the code while ensuring the test still passes.",{"type":25,"tag":30,"props":69,"children":70},{},[71],{"type":34,"value":72},"This approach ensures that each piece of code is tested, making maintenance easier and reducing the likelihood of errors.",{"type":25,"tag":37,"props":74,"children":76},{"id":75},"introduction-to-junit-and-mockito",[77],{"type":34,"value":78},"Introduction to JUnit and Mockito",{"type":25,"tag":30,"props":80,"children":81},{},[82],{"type":25,"tag":83,"props":84,"children":85},"strong",{},[86],{"type":34,"value":87},"JUnit",{"type":25,"tag":30,"props":89,"children":90},{},[91],{"type":34,"value":92},"JUnit is the most widely used unit testing framework in Java. It allows developers to write and execute automated tests efficiently.",{"type":25,"tag":30,"props":94,"children":95},{},[96],{"type":34,"value":97},"Example of a simple test with JUnit 5:",{"type":25,"tag":99,"props":100,"children":103},"pre",{"className":101,"code":102,"language":17,"meta":8,"style":8},"language-java shiki shiki-themes github-dark github-light","import org.junit.jupiter.api.Test;\nimport static org.junit.jupiter.api.Assertions.*;\n\nclass CalculatorTest {\n    @Test\n    void testSum() {\n        Calculator calc = new Calculator();\n        assertEquals(5, calc.add(2, 3));\n    }\n}\n",[104],{"type":25,"tag":15,"props":105,"children":106},{"__ignoreMap":8},[107,125,154,164,184,198,217,246,299,308],{"type":25,"tag":108,"props":109,"children":112},"span",{"class":110,"line":111},"line",1,[113,119],{"type":25,"tag":108,"props":114,"children":116},{"style":115},"--shiki-default:#F97583;--shiki-light:#D73A49",[117],{"type":34,"value":118},"import",{"type":25,"tag":108,"props":120,"children":122},{"style":121},"--shiki-default:#E1E4E8;--shiki-light:#24292E",[123],{"type":34,"value":124}," org.junit.jupiter.api.Test;\n",{"type":25,"tag":108,"props":126,"children":128},{"class":110,"line":127},2,[129,133,138,143,149],{"type":25,"tag":108,"props":130,"children":131},{"style":115},[132],{"type":34,"value":118},{"type":25,"tag":108,"props":134,"children":135},{"style":115},[136],{"type":34,"value":137}," static",{"type":25,"tag":108,"props":139,"children":140},{"style":121},[141],{"type":34,"value":142}," org.junit.jupiter.api.Assertions.",{"type":25,"tag":108,"props":144,"children":146},{"style":145},"--shiki-default:#79B8FF;--shiki-light:#005CC5",[147],{"type":34,"value":148},"*",{"type":25,"tag":108,"props":150,"children":151},{"style":121},[152],{"type":34,"value":153},";\n",{"type":25,"tag":108,"props":155,"children":157},{"class":110,"line":156},3,[158],{"type":25,"tag":108,"props":159,"children":161},{"emptyLinePlaceholder":160},true,[162],{"type":34,"value":163},"\n",{"type":25,"tag":108,"props":165,"children":167},{"class":110,"line":166},4,[168,173,179],{"type":25,"tag":108,"props":169,"children":170},{"style":115},[171],{"type":34,"value":172},"class",{"type":25,"tag":108,"props":174,"children":176},{"style":175},"--shiki-default:#B392F0;--shiki-light:#6F42C1",[177],{"type":34,"value":178}," CalculatorTest",{"type":25,"tag":108,"props":180,"children":181},{"style":121},[182],{"type":34,"value":183}," {\n",{"type":25,"tag":108,"props":185,"children":187},{"class":110,"line":186},5,[188,193],{"type":25,"tag":108,"props":189,"children":190},{"style":121},[191],{"type":34,"value":192},"    @",{"type":25,"tag":108,"props":194,"children":195},{"style":115},[196],{"type":34,"value":197},"Test\n",{"type":25,"tag":108,"props":199,"children":201},{"class":110,"line":200},6,[202,207,212],{"type":25,"tag":108,"props":203,"children":204},{"style":115},[205],{"type":34,"value":206},"    void",{"type":25,"tag":108,"props":208,"children":209},{"style":175},[210],{"type":34,"value":211}," testSum",{"type":25,"tag":108,"props":213,"children":214},{"style":121},[215],{"type":34,"value":216},"() {\n",{"type":25,"tag":108,"props":218,"children":220},{"class":110,"line":219},7,[221,226,231,236,241],{"type":25,"tag":108,"props":222,"children":223},{"style":121},[224],{"type":34,"value":225},"        Calculator calc ",{"type":25,"tag":108,"props":227,"children":228},{"style":115},[229],{"type":34,"value":230},"=",{"type":25,"tag":108,"props":232,"children":233},{"style":115},[234],{"type":34,"value":235}," new",{"type":25,"tag":108,"props":237,"children":238},{"style":175},[239],{"type":34,"value":240}," Calculator",{"type":25,"tag":108,"props":242,"children":243},{"style":121},[244],{"type":34,"value":245},"();\n",{"type":25,"tag":108,"props":247,"children":249},{"class":110,"line":248},8,[250,255,260,265,270,275,279,284,289,294],{"type":25,"tag":108,"props":251,"children":252},{"style":175},[253],{"type":34,"value":254},"        assertEquals",{"type":25,"tag":108,"props":256,"children":257},{"style":121},[258],{"type":34,"value":259},"(",{"type":25,"tag":108,"props":261,"children":262},{"style":145},[263],{"type":34,"value":264},"5",{"type":25,"tag":108,"props":266,"children":267},{"style":121},[268],{"type":34,"value":269},", calc.",{"type":25,"tag":108,"props":271,"children":272},{"style":175},[273],{"type":34,"value":274},"add",{"type":25,"tag":108,"props":276,"children":277},{"style":121},[278],{"type":34,"value":259},{"type":25,"tag":108,"props":280,"children":281},{"style":145},[282],{"type":34,"value":283},"2",{"type":25,"tag":108,"props":285,"children":286},{"style":121},[287],{"type":34,"value":288},", ",{"type":25,"tag":108,"props":290,"children":291},{"style":145},[292],{"type":34,"value":293},"3",{"type":25,"tag":108,"props":295,"children":296},{"style":121},[297],{"type":34,"value":298},"));\n",{"type":25,"tag":108,"props":300,"children":302},{"class":110,"line":301},9,[303],{"type":25,"tag":108,"props":304,"children":305},{"style":121},[306],{"type":34,"value":307},"    }\n",{"type":25,"tag":108,"props":309,"children":311},{"class":110,"line":310},10,[312],{"type":25,"tag":108,"props":313,"children":314},{"style":121},[315],{"type":34,"value":316},"}\n",{"type":25,"tag":30,"props":318,"children":319},{},[320],{"type":25,"tag":83,"props":321,"children":322},{},[323],{"type":34,"value":324},"Mockito",{"type":25,"tag":30,"props":326,"children":327},{},[328],{"type":34,"value":329},"Mockito is a framework that enables the creation of mock objects for unit testing. It is useful when testing components that depend on external services, such as databases or APIs.",{"type":25,"tag":30,"props":331,"children":332},{},[333],{"type":34,"value":334},"Example using Mockito:",{"type":25,"tag":99,"props":336,"children":338},{"className":101,"code":337,"language":17,"meta":8,"style":8},"import org.junit.jupiter.api.Test;\nimport org.mockito.Mockito;\nimport static org.mockito.Mockito.*;\nimport static org.junit.jupiter.api.Assertions.*;\n\nclass ServiceTest {\n    @Test\n    void testService() {\n        ExternalService serviceMock = mock(ExternalService.class);\n        when(serviceMock.getData()).thenReturn(\"Mocked data\");\n        \n        Client client = new Client(serviceMock);\n        assertEquals(\"Mocked data\", client.getInformation());\n    }\n}\n\n",[339],{"type":25,"tag":15,"props":340,"children":341},{"__ignoreMap":8},[342,353,365,389,412,419,435,446,462,484,527,536,563,594,602],{"type":25,"tag":108,"props":343,"children":344},{"class":110,"line":111},[345,349],{"type":25,"tag":108,"props":346,"children":347},{"style":115},[348],{"type":34,"value":118},{"type":25,"tag":108,"props":350,"children":351},{"style":121},[352],{"type":34,"value":124},{"type":25,"tag":108,"props":354,"children":355},{"class":110,"line":127},[356,360],{"type":25,"tag":108,"props":357,"children":358},{"style":115},[359],{"type":34,"value":118},{"type":25,"tag":108,"props":361,"children":362},{"style":121},[363],{"type":34,"value":364}," org.mockito.Mockito;\n",{"type":25,"tag":108,"props":366,"children":367},{"class":110,"line":156},[368,372,376,381,385],{"type":25,"tag":108,"props":369,"children":370},{"style":115},[371],{"type":34,"value":118},{"type":25,"tag":108,"props":373,"children":374},{"style":115},[375],{"type":34,"value":137},{"type":25,"tag":108,"props":377,"children":378},{"style":121},[379],{"type":34,"value":380}," org.mockito.Mockito.",{"type":25,"tag":108,"props":382,"children":383},{"style":145},[384],{"type":34,"value":148},{"type":25,"tag":108,"props":386,"children":387},{"style":121},[388],{"type":34,"value":153},{"type":25,"tag":108,"props":390,"children":391},{"class":110,"line":166},[392,396,400,404,408],{"type":25,"tag":108,"props":393,"children":394},{"style":115},[395],{"type":34,"value":118},{"type":25,"tag":108,"props":397,"children":398},{"style":115},[399],{"type":34,"value":137},{"type":25,"tag":108,"props":401,"children":402},{"style":121},[403],{"type":34,"value":142},{"type":25,"tag":108,"props":405,"children":406},{"style":145},[407],{"type":34,"value":148},{"type":25,"tag":108,"props":409,"children":410},{"style":121},[411],{"type":34,"value":153},{"type":25,"tag":108,"props":413,"children":414},{"class":110,"line":186},[415],{"type":25,"tag":108,"props":416,"children":417},{"emptyLinePlaceholder":160},[418],{"type":34,"value":163},{"type":25,"tag":108,"props":420,"children":421},{"class":110,"line":200},[422,426,431],{"type":25,"tag":108,"props":423,"children":424},{"style":115},[425],{"type":34,"value":172},{"type":25,"tag":108,"props":427,"children":428},{"style":175},[429],{"type":34,"value":430}," ServiceTest",{"type":25,"tag":108,"props":432,"children":433},{"style":121},[434],{"type":34,"value":183},{"type":25,"tag":108,"props":436,"children":437},{"class":110,"line":219},[438,442],{"type":25,"tag":108,"props":439,"children":440},{"style":121},[441],{"type":34,"value":192},{"type":25,"tag":108,"props":443,"children":444},{"style":115},[445],{"type":34,"value":197},{"type":25,"tag":108,"props":447,"children":448},{"class":110,"line":248},[449,453,458],{"type":25,"tag":108,"props":450,"children":451},{"style":115},[452],{"type":34,"value":206},{"type":25,"tag":108,"props":454,"children":455},{"style":175},[456],{"type":34,"value":457}," testService",{"type":25,"tag":108,"props":459,"children":460},{"style":121},[461],{"type":34,"value":216},{"type":25,"tag":108,"props":463,"children":464},{"class":110,"line":301},[465,470,474,479],{"type":25,"tag":108,"props":466,"children":467},{"style":121},[468],{"type":34,"value":469},"        ExternalService serviceMock ",{"type":25,"tag":108,"props":471,"children":472},{"style":115},[473],{"type":34,"value":230},{"type":25,"tag":108,"props":475,"children":476},{"style":175},[477],{"type":34,"value":478}," mock",{"type":25,"tag":108,"props":480,"children":481},{"style":121},[482],{"type":34,"value":483},"(ExternalService.class);\n",{"type":25,"tag":108,"props":485,"children":486},{"class":110,"line":310},[487,492,497,502,507,512,516,522],{"type":25,"tag":108,"props":488,"children":489},{"style":175},[490],{"type":34,"value":491},"        when",{"type":25,"tag":108,"props":493,"children":494},{"style":121},[495],{"type":34,"value":496},"(serviceMock.",{"type":25,"tag":108,"props":498,"children":499},{"style":175},[500],{"type":34,"value":501},"getData",{"type":25,"tag":108,"props":503,"children":504},{"style":121},[505],{"type":34,"value":506},"()).",{"type":25,"tag":108,"props":508,"children":509},{"style":175},[510],{"type":34,"value":511},"thenReturn",{"type":25,"tag":108,"props":513,"children":514},{"style":121},[515],{"type":34,"value":259},{"type":25,"tag":108,"props":517,"children":519},{"style":518},"--shiki-default:#9ECBFF;--shiki-light:#032F62",[520],{"type":34,"value":521},"\"Mocked data\"",{"type":25,"tag":108,"props":523,"children":524},{"style":121},[525],{"type":34,"value":526},");\n",{"type":25,"tag":108,"props":528,"children":530},{"class":110,"line":529},11,[531],{"type":25,"tag":108,"props":532,"children":533},{"style":121},[534],{"type":34,"value":535},"        \n",{"type":25,"tag":108,"props":537,"children":539},{"class":110,"line":538},12,[540,545,549,553,558],{"type":25,"tag":108,"props":541,"children":542},{"style":121},[543],{"type":34,"value":544},"        Client client ",{"type":25,"tag":108,"props":546,"children":547},{"style":115},[548],{"type":34,"value":230},{"type":25,"tag":108,"props":550,"children":551},{"style":115},[552],{"type":34,"value":235},{"type":25,"tag":108,"props":554,"children":555},{"style":175},[556],{"type":34,"value":557}," Client",{"type":25,"tag":108,"props":559,"children":560},{"style":121},[561],{"type":34,"value":562},"(serviceMock);\n",{"type":25,"tag":108,"props":564,"children":566},{"class":110,"line":565},13,[567,571,575,579,584,589],{"type":25,"tag":108,"props":568,"children":569},{"style":175},[570],{"type":34,"value":254},{"type":25,"tag":108,"props":572,"children":573},{"style":121},[574],{"type":34,"value":259},{"type":25,"tag":108,"props":576,"children":577},{"style":518},[578],{"type":34,"value":521},{"type":25,"tag":108,"props":580,"children":581},{"style":121},[582],{"type":34,"value":583},", client.",{"type":25,"tag":108,"props":585,"children":586},{"style":175},[587],{"type":34,"value":588},"getInformation",{"type":25,"tag":108,"props":590,"children":591},{"style":121},[592],{"type":34,"value":593},"());\n",{"type":25,"tag":108,"props":595,"children":597},{"class":110,"line":596},14,[598],{"type":25,"tag":108,"props":599,"children":600},{"style":121},[601],{"type":34,"value":307},{"type":25,"tag":108,"props":603,"children":605},{"class":110,"line":604},15,[606],{"type":25,"tag":108,"props":607,"children":608},{"style":121},[609],{"type":34,"value":316},{"type":25,"tag":37,"props":611,"children":613},{"id":612},"tdd-in-action-a-practical-example",[614],{"type":34,"value":615},"TDD in Action: A Practical Example",{"type":25,"tag":30,"props":617,"children":618},{},[619],{"type":34,"value":620},"Let's say we need to develop a user management service. First, we write a failing test:",{"type":25,"tag":99,"props":622,"children":624},{"className":101,"code":623,"language":17,"meta":8,"style":8},"@Test\nvoid testAddUser() {\n    UserRepository repoMock = mock(UserRepository.class);\n    UserService service = new UserService(repoMock);\n    \n    User user = new User(\"John\", \"john@example.com\");\n    when(repoMock.save(user)).thenReturn(true);\n    \n    assertTrue(service.registerUser(user));\n} \n",[625],{"type":25,"tag":15,"props":626,"children":627},{"__ignoreMap":8},[628,640,657,678,704,712,755,795,802,825],{"type":25,"tag":108,"props":629,"children":630},{"class":110,"line":111},[631,636],{"type":25,"tag":108,"props":632,"children":633},{"style":121},[634],{"type":34,"value":635},"@",{"type":25,"tag":108,"props":637,"children":638},{"style":115},[639],{"type":34,"value":197},{"type":25,"tag":108,"props":641,"children":642},{"class":110,"line":127},[643,648,653],{"type":25,"tag":108,"props":644,"children":645},{"style":115},[646],{"type":34,"value":647},"void",{"type":25,"tag":108,"props":649,"children":650},{"style":175},[651],{"type":34,"value":652}," testAddUser",{"type":25,"tag":108,"props":654,"children":655},{"style":121},[656],{"type":34,"value":216},{"type":25,"tag":108,"props":658,"children":659},{"class":110,"line":156},[660,665,669,673],{"type":25,"tag":108,"props":661,"children":662},{"style":121},[663],{"type":34,"value":664},"    UserRepository repoMock ",{"type":25,"tag":108,"props":666,"children":667},{"style":115},[668],{"type":34,"value":230},{"type":25,"tag":108,"props":670,"children":671},{"style":175},[672],{"type":34,"value":478},{"type":25,"tag":108,"props":674,"children":675},{"style":121},[676],{"type":34,"value":677},"(UserRepository.class);\n",{"type":25,"tag":108,"props":679,"children":680},{"class":110,"line":166},[681,686,690,694,699],{"type":25,"tag":108,"props":682,"children":683},{"style":121},[684],{"type":34,"value":685},"    UserService service ",{"type":25,"tag":108,"props":687,"children":688},{"style":115},[689],{"type":34,"value":230},{"type":25,"tag":108,"props":691,"children":692},{"style":115},[693],{"type":34,"value":235},{"type":25,"tag":108,"props":695,"children":696},{"style":175},[697],{"type":34,"value":698}," UserService",{"type":25,"tag":108,"props":700,"children":701},{"style":121},[702],{"type":34,"value":703},"(repoMock);\n",{"type":25,"tag":108,"props":705,"children":706},{"class":110,"line":186},[707],{"type":25,"tag":108,"props":708,"children":709},{"style":121},[710],{"type":34,"value":711},"    \n",{"type":25,"tag":108,"props":713,"children":714},{"class":110,"line":200},[715,720,724,728,733,737,742,746,751],{"type":25,"tag":108,"props":716,"children":717},{"style":121},[718],{"type":34,"value":719},"    User user ",{"type":25,"tag":108,"props":721,"children":722},{"style":115},[723],{"type":34,"value":230},{"type":25,"tag":108,"props":725,"children":726},{"style":115},[727],{"type":34,"value":235},{"type":25,"tag":108,"props":729,"children":730},{"style":175},[731],{"type":34,"value":732}," User",{"type":25,"tag":108,"props":734,"children":735},{"style":121},[736],{"type":34,"value":259},{"type":25,"tag":108,"props":738,"children":739},{"style":518},[740],{"type":34,"value":741},"\"John\"",{"type":25,"tag":108,"props":743,"children":744},{"style":121},[745],{"type":34,"value":288},{"type":25,"tag":108,"props":747,"children":748},{"style":518},[749],{"type":34,"value":750},"\"john@example.com\"",{"type":25,"tag":108,"props":752,"children":753},{"style":121},[754],{"type":34,"value":526},{"type":25,"tag":108,"props":756,"children":757},{"class":110,"line":219},[758,763,768,773,778,782,786,791],{"type":25,"tag":108,"props":759,"children":760},{"style":175},[761],{"type":34,"value":762},"    when",{"type":25,"tag":108,"props":764,"children":765},{"style":121},[766],{"type":34,"value":767},"(repoMock.",{"type":25,"tag":108,"props":769,"children":770},{"style":175},[771],{"type":34,"value":772},"save",{"type":25,"tag":108,"props":774,"children":775},{"style":121},[776],{"type":34,"value":777},"(user)).",{"type":25,"tag":108,"props":779,"children":780},{"style":175},[781],{"type":34,"value":511},{"type":25,"tag":108,"props":783,"children":784},{"style":121},[785],{"type":34,"value":259},{"type":25,"tag":108,"props":787,"children":788},{"style":145},[789],{"type":34,"value":790},"true",{"type":25,"tag":108,"props":792,"children":793},{"style":121},[794],{"type":34,"value":526},{"type":25,"tag":108,"props":796,"children":797},{"class":110,"line":248},[798],{"type":25,"tag":108,"props":799,"children":800},{"style":121},[801],{"type":34,"value":711},{"type":25,"tag":108,"props":803,"children":804},{"class":110,"line":301},[805,810,815,820],{"type":25,"tag":108,"props":806,"children":807},{"style":175},[808],{"type":34,"value":809},"    assertTrue",{"type":25,"tag":108,"props":811,"children":812},{"style":121},[813],{"type":34,"value":814},"(service.",{"type":25,"tag":108,"props":816,"children":817},{"style":175},[818],{"type":34,"value":819},"registerUser",{"type":25,"tag":108,"props":821,"children":822},{"style":121},[823],{"type":34,"value":824},"(user));\n",{"type":25,"tag":108,"props":826,"children":827},{"class":110,"line":310},[828],{"type":25,"tag":108,"props":829,"children":830},{"style":121},[831],{"type":34,"value":316},{"type":25,"tag":30,"props":833,"children":834},{},[835],{"type":34,"value":836},"Next, we implement the minimal functionality required for the test to pass:",{"type":25,"tag":99,"props":838,"children":840},{"className":101,"code":839,"language":17,"meta":8,"style":8},"class UserService {\nprivate final UserRepository repository;\n    \n    public UserService(UserRepository repository) {\n        this.repository = repository;\n    }\n    \n    public boolean registerUser(User user) {\n        return repository.save(user);\n    }\n}\n",[841],{"type":25,"tag":15,"props":842,"children":843},{"__ignoreMap":8},[844,859,877,884,912,934,941,948,979,1001,1008],{"type":25,"tag":108,"props":845,"children":846},{"class":110,"line":111},[847,851,855],{"type":25,"tag":108,"props":848,"children":849},{"style":115},[850],{"type":34,"value":172},{"type":25,"tag":108,"props":852,"children":853},{"style":175},[854],{"type":34,"value":698},{"type":25,"tag":108,"props":856,"children":857},{"style":121},[858],{"type":34,"value":183},{"type":25,"tag":108,"props":860,"children":861},{"class":110,"line":127},[862,867,872],{"type":25,"tag":108,"props":863,"children":864},{"style":115},[865],{"type":34,"value":866},"private",{"type":25,"tag":108,"props":868,"children":869},{"style":115},[870],{"type":34,"value":871}," final",{"type":25,"tag":108,"props":873,"children":874},{"style":121},[875],{"type":34,"value":876}," UserRepository repository;\n",{"type":25,"tag":108,"props":878,"children":879},{"class":110,"line":156},[880],{"type":25,"tag":108,"props":881,"children":882},{"style":121},[883],{"type":34,"value":711},{"type":25,"tag":108,"props":885,"children":886},{"class":110,"line":166},[887,892,896,901,907],{"type":25,"tag":108,"props":888,"children":889},{"style":115},[890],{"type":34,"value":891},"    public",{"type":25,"tag":108,"props":893,"children":894},{"style":175},[895],{"type":34,"value":698},{"type":25,"tag":108,"props":897,"children":898},{"style":121},[899],{"type":34,"value":900},"(UserRepository ",{"type":25,"tag":108,"props":902,"children":904},{"style":903},"--shiki-default:#FFAB70;--shiki-light:#E36209",[905],{"type":34,"value":906},"repository",{"type":25,"tag":108,"props":908,"children":909},{"style":121},[910],{"type":34,"value":911},") {\n",{"type":25,"tag":108,"props":913,"children":914},{"class":110,"line":186},[915,920,925,929],{"type":25,"tag":108,"props":916,"children":917},{"style":145},[918],{"type":34,"value":919},"        this",{"type":25,"tag":108,"props":921,"children":922},{"style":121},[923],{"type":34,"value":924},".repository ",{"type":25,"tag":108,"props":926,"children":927},{"style":115},[928],{"type":34,"value":230},{"type":25,"tag":108,"props":930,"children":931},{"style":121},[932],{"type":34,"value":933}," repository;\n",{"type":25,"tag":108,"props":935,"children":936},{"class":110,"line":200},[937],{"type":25,"tag":108,"props":938,"children":939},{"style":121},[940],{"type":34,"value":307},{"type":25,"tag":108,"props":942,"children":943},{"class":110,"line":219},[944],{"type":25,"tag":108,"props":945,"children":946},{"style":121},[947],{"type":34,"value":711},{"type":25,"tag":108,"props":949,"children":950},{"class":110,"line":248},[951,955,960,965,970,975],{"type":25,"tag":108,"props":952,"children":953},{"style":115},[954],{"type":34,"value":891},{"type":25,"tag":108,"props":956,"children":957},{"style":115},[958],{"type":34,"value":959}," boolean",{"type":25,"tag":108,"props":961,"children":962},{"style":175},[963],{"type":34,"value":964}," registerUser",{"type":25,"tag":108,"props":966,"children":967},{"style":121},[968],{"type":34,"value":969},"(User ",{"type":25,"tag":108,"props":971,"children":972},{"style":903},[973],{"type":34,"value":974},"user",{"type":25,"tag":108,"props":976,"children":977},{"style":121},[978],{"type":34,"value":911},{"type":25,"tag":108,"props":980,"children":981},{"class":110,"line":301},[982,987,992,996],{"type":25,"tag":108,"props":983,"children":984},{"style":115},[985],{"type":34,"value":986},"        return",{"type":25,"tag":108,"props":988,"children":989},{"style":121},[990],{"type":34,"value":991}," repository.",{"type":25,"tag":108,"props":993,"children":994},{"style":175},[995],{"type":34,"value":772},{"type":25,"tag":108,"props":997,"children":998},{"style":121},[999],{"type":34,"value":1000},"(user);\n",{"type":25,"tag":108,"props":1002,"children":1003},{"class":110,"line":310},[1004],{"type":25,"tag":108,"props":1005,"children":1006},{"style":121},[1007],{"type":34,"value":307},{"type":25,"tag":108,"props":1009,"children":1010},{"class":110,"line":529},[1011],{"type":25,"tag":108,"props":1012,"children":1013},{"style":121},[1014],{"type":34,"value":316},{"type":25,"tag":30,"props":1016,"children":1017},{},[1018],{"type":34,"value":1019},"Finally, we refactor the code if necessary while ensuring all tests continue to pass.",{"type":25,"tag":37,"props":1021,"children":1023},{"id":1022},"conclusion",[1024],{"type":34,"value":1025},"Conclusion",{"type":25,"tag":30,"props":1027,"children":1028},{},[1029],{"type":34,"value":1030},"Using TDD alongside tools like JUnit and Mockito not only improves software quality but also plays a crucial role in technical interviews. Many companies seek developers who understand and apply automated testing, as it ensures robust and maintainable code. Practicing TDD can set you apart in your next interview and enhance your career as a Java developer.",{"type":25,"tag":37,"props":1032,"children":1034},{"id":1033},"further-reading",[1035],{"type":34,"value":1036},"Further Reading",{"type":25,"tag":30,"props":1038,"children":1039},{},[1040],{"type":34,"value":1041},"To deepen your understanding of TDD, JUnit, and Mockito, consider exploring the following resources:",{"type":25,"tag":49,"props":1043,"children":1044},{},[1045,1057,1067],{"type":25,"tag":53,"props":1046,"children":1047},{},[1048],{"type":25,"tag":1049,"props":1050,"children":1054},"a",{"href":1051,"rel":1052},"https://junit.org/junit5/docs/current/user-guide/",[1053],"nofollow",[1055],{"type":34,"value":1056},"JUnit 5 User Guide",{"type":25,"tag":53,"props":1058,"children":1059},{},[1060],{"type":25,"tag":1049,"props":1061,"children":1064},{"href":1062,"rel":1063},"https://site.mockito.org/",[1053],[1065],{"type":34,"value":1066},"Mockito Documentation",{"type":25,"tag":53,"props":1068,"children":1069},{},[1070],{"type":25,"tag":1049,"props":1071,"children":1074},{"href":1072,"rel":1073},"https://www.oreilly.com/library/view/test-driven-development/0321146530/",[1053],[1075],{"type":34,"value":1076},"Test-Driven Development by Example - Kent Beck",{"type":25,"tag":30,"props":1078,"children":1079},{},[1080],{"type":34,"value":1081},"Mastering TDD will not only improve your coding skills but also help you build more reliable and maintainable software systems.",{"type":25,"tag":1083,"props":1084,"children":1085},"style",{},[1086],{"type":34,"value":1087},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}",{"title":8,"searchDepth":127,"depth":127,"links":1089},[1090,1091,1092,1093,1094],{"id":39,"depth":127,"text":42},{"id":75,"depth":127,"text":78},{"id":612,"depth":127,"text":615},{"id":1022,"depth":127,"text":1025},{"id":1033,"depth":127,"text":1036},"markdown","content:posts:tdd-testing.md","content","posts/tdd-testing.md","posts/tdd-testing","md",1790510065404]