Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests more readable #110

Open
Yi-Tseng opened this issue Oct 12, 2020 · 2 comments
Open

Make tests more readable #110

Yi-Tseng opened this issue Oct 12, 2020 · 2 comments
Assignees

Comments

@Yi-Tseng
Copy link
Collaborator

Yi-Tseng commented Oct 12, 2020

Now we are using multiple layers of for-loop to create combinations of input parameters, for example:

@autocleanup
def doRunTest(self, param1, param2, ...., paramN):
    # run the test with parameters

def runTest(self):
    for param1 in [...]
        for param2 in [...]
            # skip test for some combanitaions
            if param1 == A and param2 == B:
                continue
            for param3 in [....]
                doRunTest(param1, param2, ..., paramN)

See comment below

We might be able to use python decorator to make the test more readable, for example:

@autocleanup
@test_param('param1', .......)
@test_param('param2', .......)
@skip_test_if(param1=A, param2=B)
@test_param('param3', .......)
def doRunTest(self, param1, param2, param3):
    # run the test with parameters

def runTest(self):
    doRunTest()
@ccascone
Copy link
Member

ccascone commented Oct 12, 2020

That long list of annotations is not very appealing. It looks like we are defining a meta-language, which can easily become unmanageable.

How about we define a common structure for test arguments, say test_args, and functions to generate that? test_args would include things like the pkt type (test_args.pkt_type), vlan configuration (test_args.ig/eg_vlan_tagged), whether the next hop is spine, etc.

for test_args in self.get_test_args(<high level args>):
    print(test_args) # pkt_type=tcp, vlan=tagget->untagged, next_hop_spine=true, ...
    self.doRunTest(test_args)

An example of <high level args> could be:

  • spine_only=true to generate arguments that make sense for a spine switch (eg., interfaces always assumed vlan untagged);
  • int_report=true to generate args that make sense for a class that checks report generation;
  • etc.

@Yi-Tseng
Copy link
Collaborator Author

Having a function to generate all possible test parameters also sounds like a good idea.
The reason I was thinking about using decorators for the function is that it is easier to custom or modify all input parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants