In California family law cases, children at times can address the court to explain their preference when parents do not agree on matters of custody. Family Code 3042 makes it clear that a child of 14 may be permitted to address the court if the court okays it. The court can so no if they decide it’s not in the best interests of the child.
That doesn’t mean younger kids can’t do it. The child’s sincerity, bearing, and degree of maturity are important and should be judged.
Nothing in the law requires a court to hear the child, and with good reason. In my experience, parties who are eager to have the child testify are pressuring the child to choose sides. Only in rare cases do I think it’s appropriate for a child to testify against a parent. In all other cases, the court can appoint experts who can speak with the child and get their viewpoint on what is happening.