Programming Phoenix LiveView: Thoughts on Chapter 10 ('Test Your Live Views') and potential improvements

I would like to share my thoughts on working through chapter 10 (‘Test Your Live Views’):

  • Because I worked through the previous exercises without updating the tests, many of my tests failed when I arrived at this chapter.

    • Suggested mitigation: Warn the user that this may happen, and that we should run only the tests we are working on at the given moment, e.g. mix test test/pento_web/live/survey_results_live.exs. (This functionality is used at the bottom of PDF page 305, but I believe it should be explicitly highlighted whenever the tests are to be run.) This will keep the user focused on the task at hand and prevent them from spending time seeing a terminal full of red text (or fixing tests that may have broken as a side effect whatever may have happened while they were working through the book).
    • Alternative (not as good IMO) mitigation: With each set of exercises, add a bonus exercise about making sure the tests are still passing. I think this solution is less desireable since it detracts from the main point of the book (LiveView, not testing). Also it increases the likelihood of some user-made changes clashing with the material described throughout the book (and of the additional effort of unsnarling their changes and the fixing tests they wrote).
  • As a corollary to the previous point, I think the usage of mix test should be described a little more explicitly throughout the chapter. I have only completed the section on unit testing so far, but each step of the book assumes the user already knows how to run the tests. (Which they definitely should. I am not saying they need to have their hand held to the degree that they need to be explained how mix test works, especially when it has been used earlier in the book, and the book is not an introduction to Elixir or Phoenix.) I believe that the addition of explicit commands such as mix test test/pento_web/live/survey_results_live_test.exs will help to circumvent the “broken tests” issue I described above.

Hello and thanks for your feedback, it’s much appreciated! I’ll add a warning like you suggested. You can look out for that in the next release which should be in the next few weeks.

Hmm actually now that I’m looking at the chapter, I see that there are no commands that instruct the user to run only mix test. All instructions tell the user to run the specific test file, and often a specific line number for that test file. I can still add a mention that if the reader does run mix test though, they may expect some failing tests.

There is an instruction to run mix test in chapter 2. (I skimmed chapter 10 already a while back, I think it said somewhere that testing hadn’t been mentioned yet, not entirely true, fortunately :slight_smile: . I’ll probably continuing from chapter 2 in a few weeks, once the update is out. I’ll be running tests all the time (using murex/tcr or mix test when I can’t make a small step). Shall I post progress somewhere? With the phoenix guides I experienced what @arcanemachine mentioned - 30 odd tests failed when I was done with them, it took a couple of hours to fix.
Looking forward to the updated version, must be hard work with all the changes in Phoenix.