Closed-form analytical solutions are obtained for ray tracing in several types of optically anisotropic inhomogeneous media whose optical properties are characterized by a matrix form of the inhomogeneous dielectric tensor in principal coordinates. The first solution is for anisotropic axial media, the second solution is for meridional rays in epsilon-negative metamaterial, and the third solution is an approximate one for rectangular lenses fabricated by molding procedures. The validation of numerical ray-tracing procedures for optically anisotropic inhomogeneous media was widely ignored since the solution was not available, and thus the present solutions are also useful for the validation. Furthermore, as examples of validation, ray trajectories are calculated by the closed-form solutions, and their results are compared with those obtained by a numerical solution of the geodesic equation which can be interpreted as a generalized ray equation.