The problem with dynamic code is that it's harder to understand and debug. So if possible, we should try to use static one.
You may put the class within the test case file. Thanks.