Always expanded menu items not showing up expanded in custom menu
I have investigated this a bit more and made a bug report on Drupal.org. It turns out the 'menu_expanded' variable is basically a redundant layer of caching which must be set by _menu_set_expanded_menus whenever the cache is cleared. However, if Drupal tries to call that function more than once in a single request, it will be registered as a shutdown callback instead of called immediately. This would work fine most of the time in normal use, but during test cases the shutdown function won't get called until after the tests are over.

Knowing that most of the time this operation will handle itself correctly, and that even if it doesn't it's just a cache clear away from being fixed, I've decided it is acceptable to add a direct call to _menu_set_expanded_menus in the setUp function like so:

function setUp() {
  parent::setUp('custom');
  // Call this function now to set up expanded menu item processing. Normally
  // we could wait for it to be called in a shutdown function added during
  // the menu rebuild in parent::setUp() above, but in this case it must be
  // handled before the tests are run.
  _menu_set_expanded_menus();
}