Just because you outrank another officer doesn't mean you default to taking command over them...especially if one officer is a Command officer (TNG redshirt) and the other isn't. Technically the captain can designate anyone they want to be in command of the ship, anyhow.
As for why Data never took the test...you'd have to ask him.
Well, in "Genesis" there was the scene with Troi taking command of the ship while Picard and Data went chasing after the torpedo.
I mean, I'm glad she got to command the ship for a second time but Riker was still on board so why not put him in command? Unless it wasn't his watch...
The way I'm understanding it is this...
Since Riker is a red shirt and Troi is a blue shirt, yet they both bear the same Commander rank, I still can't see Troi outranking Riker.
Data is a Lt. Commander and all episodes following "Thine Own Self" Troi is a Commander, so does that mean that if Troi gives Data an order he has to obey it?
I still can't get over Picard's absence in "Thine Own Self" except for the last couple of minutes in the episode, given that he's the captain and that's such a big role.