In my last article on the Long Refactoring series, I elided the process I went through to solve the bug. While preparing to turn the articles into a presentation, I went through the steps myself again, and came across the bug. When I was writing the articles, I was pressed for time, and didn’t go through the process of solving it step by step, which in turn means there is a gap between the pre-and-post states of the code: you can’t get there from here.
Let me take it from where I mentioned that I found a bug, and added the unit test that shows it.
Category Archives: Testing
The development cycle
how to clean up code.
- run your code to make sure it works
- while (work_to_do){
- make a small change
- test it
- commit to git
- }
- push to git server on local branch
- try it on another machine
- collapse git commits for code review
- test
- post for code review
How to add a new feature
- run your code make sure it works
- while (work_to_do){
- write a small test
- while (test doesn’t pass){
- make a small change
- test it
- }
- commit to git
- }
- push to git server on local branch
- try it on another machine
- collapse git commits for code review
- test
- post for code review
How Did I break my Code
Something I did in a commit broke my code. I have a git bisect that shows me the last good commit and the first bad one.
Continue readingRemote build of the Linux Kernel via Ironic
Ampere Computing chips run the ARM64 instruction set. My laptop is a Dell running x86_64. In order to edit locally, but build remotely, I make use of servers in our datacenter. These are the steps I am taking.
Continue readingLong Refactoring: pep8
While writing the last article, I noticed that I had made a bunch of little changes to the files without explicitly meaning to. I didn’t include them in the diffs. However, on my screen, I have a bunch of changes that appear to be…not changes:
Continue readingLong Refactoring: Extract Read
The typical approach to Data handling is
- read
- munge
- write
We want out code to reflect that structure. In doing so, we make it much easier to adapt the code to read from different sources and write to different destinations.
Continue readingLong Refactoring: First New Unit Test
The heart of the code is the call to solve a single puzzle; the function tree_to_solution_string. We want to write a test that runs just this function. Getting there is not so easy.
This method is buried deep within the class SudokuSolver. But creating one of these essentially runs the entire code. In fact, we can redo our original test to run the code as a python call as opposed to a subprocess call. Lets’ start with that.
Continue readingLong Refactoring: Call a Unit Test
Our test takes 5 seconds to run. That is not horrible, but it does not bode well for when we write more tests. We don’t want to explode that number, and we want to be able to write more focused test. I’m going to do some project setup that will enable us to do more development, including fine grained unit tests.
I’m going to start by using tox.
Continue readingA Long Refactoring: Introduction
Congratulations, you got your code to run! You are done! Ship it!. Just don’t expect to be able to read it next month. You need to maintain it. You need to add new features. It is a mess.
Give yourself a well deserved break. Then come back to it.
Continue readingTesting if a patch has test coverage
When a user requests a code review, the review is responsible for making sure that the code is tested. While the quality of the tests is a subjective matter, their presences is not; either they are there or they are not there. If they are not there, it is on the developer to explain why or why not.
Not every line of code is testable. Not every test is intelligent. But, at a minimum, a test should ensure that the code in a patch is run at least once, without an unexpected exception.