TDD in YUK-RECYCLE

Donny Samuel
PPL A-4 YUK RECYCLE
3 min readApr 2, 2019

Hi, it’s Donny !

In this section, we will talk about software testing and create test for our code. This article will give an example from YUK-RECYCLE app.

Test-Driven Development

Basically you need to write the test before you code. Test-driven development is a development concept when the tests are written before the code. In practical, Developer start the development process by writing unit-test before writing actual code implementation. By doing this, we ensure that However the code implement, It’s not affecting the final goal.

3 Phases of TDD

Red, Green and Refactor is the three phase of Test Driven Development and this the sequence that get followed while writing code.

RED

The developer has to write test but there’re no any code to test. You write the first test even without writing code to declare class and method so basically your test will not even compile. This is again the same as having test fail. Once you fix the compilation error, then the next is to execute your test to fail it. This is where you get a red flag by your unit test framework.

GREEN

The green phase is where you actually write an actual code but you only allowed to write just enough code. The purpose is only to get pass thew test so you only have to write a code that compatible with the test.

REFACTOR

In refactor phase the point is you change the code to a better implementation without changing the purpose of the code.

TDD in YUK-RECYCLE

First thing to test in front end are the widget wether there are any widget on the page. We can test by text, or amount.

This is the example of the widget. This is a widget to input name on it. We put a placeholder to give a hint to the users.

This is an example of a button widget.

This is a function to run test from register page.

Conclusion

TDD is a practice makes perfect. At first we will super slow when making test first. But if we can do TDD, our code will become more efficient and can clean un-needed code. Our TDD implementation might be not perfect, but we will make it better on the next sprint. Thank you for reading! *D*

--

--

Donny Samuel
PPL A-4 YUK RECYCLE

CS Student at University of Indonesia | UI/UX, Tech Enthusiast