Test Unittests first

Beware, this pull request also contains the PR of @davisagli 
As it is an extension of his stuff
Again, I suggest `layers = sorted(layers, key=layer_sort_key, reverse=True)` instead of the two lines.