I think xpath would be the way to go on this. Something like
string testQuizID = driver.findElement(By.xpath("//span[contains(text(), 'TestQuiz')]/ancestor::li[1]")).getAttribute("id");
I'm not sure what language you're using, this is java syntax.