Expert Refactoring - Introducing duplication to remove duplication

Опубликовано: 01 Сентябрь 2023
на канале: Pairing with Duncan
487
29

Our acceptance test strategy here on Team Gilded Rose has been a bit haphazard. We have some tests that talk directly to our app object, others use http4k in memory to interact with the routes, and yet others fire up a server and use Playwright to pretend to be a user with a web browser.

It would be nice if we could write our tests once, and then run them in all three ways. Now we could develop that functionality from scratch, but if you are a regular viewer, it won’t surprise you to find out that we are going to refactor our existing tests until we reach this nirvana.

This is I think the most advanced refactoring I’ve presented so far. It involves removing duplication by gradually changing multiple methods until they are all in the same shape. Once they are the same shape, we can use our usual techniques to remove duplication and find an abstraction.

In this episode

00:01:02 Addressing a bug in our test code
00:01:41 A mini postmortem
00:02:27 Testing our testing
00:04:35 Removing duplication makes things less error-prone
00:04:56 IntelliJ refactoring bug
00:05:22 Reviewing our test duplication
00:06:56 Making the duplication more obvious
00:07:22 Making all the assertions the same shape
00:11:47 Making all the inputs the same shape
00:19:46 Making all the actions the same shape
00:23:51 Now all our tests are the same shape
00:24:27 Extracting a contract class to hold all the tests
00:25:24 IntelliJ refactoring bug
00:29:34 Now we have multiple tests run multiple ways
00:30:53 One test can't work in the browser
00:32:40 Intellij import bug
00:33:44 One last removal of duplication
00:34:32 It turns out that the browser tests are flakey - who could have predicted that?
00:35:25 Check in
00:35:44 Review

This is part 90 of an exploration of where a Test Driven Development implementation of the Gilded Rose stock control system might take us in Kotlin. You can see the whole series as a playlist
   • All Gilded Rose Episodes  
and the code on GitHub
https://github.com/dmcg/gilded-rose-tdd

If you like this, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook
(http://java-to-kotlin.dev). It's about far more than just the syntax differences between the languages - it shows how to upgrade your thinking to a more functional style.


Смотрите видео Expert Refactoring - Introducing duplication to remove duplication онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Pairing with Duncan 01 Сентябрь 2023, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 487 раз и оно понравилось 29 людям.