You can do [model based testing](https://en.wikipedia.org/wiki/Model-based_testing) (e.g., https://mbt.informal.systems/)
But this exact problem is why I am more interested in approaches that integrate specification and implementation into a single (dialectical) process (e.g., via type-theoretic methods).