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

Unit Test Generator #473

Open
vsalvino opened this issue Feb 18, 2022 · 2 comments
Open

Unit Test Generator #473

vsalvino opened this issue Feb 18, 2022 · 2 comments
Labels
Type: Enhancement New feature or functionality change

Comments

@vsalvino
Copy link
Contributor

As part of the project_template, I think it would be beneficial to also create a template for unit tests, to instantly provide some minimal coverage and to make it as easy as possible for developers to get started writing more advanced tests.

The biggest barrier to entry is often times just setting all the test framework up, and remembering how to do it.

Two ideas here, not necessarily mutually exclusive:

  1. A generic test which loads all known models based on CoderedPage (we already have this list). Loops through them and creates an object with a title and some other basic fields, and asserts a successful GET response. The advantage is that you get free unit tests; the disadvantage is that it would still require writing custom unit tests for actual functionality.

  2. Similar to makemigrations, a management command maketests which creates a boilerplate unit test file for each model that doesn't already have a test file. This would be super easy to implement as it could essentially just copy a python template into the folder. The result would be a basic unit test similar to 1 above, but with the intention that the developer can start customizing it to do more.

As part of this we would also need to provide test tooling in requirements-dev.txt, similar to how the sass template works.

While 1 above is a bit "cooler", I think 2 is a more useful approach, as it would give the same coverage as 1, but be a lot easier to understand and add to over time.

@vsalvino vsalvino added the Type: Enhancement New feature or functionality change label Feb 18, 2022
@vsalvino
Copy link
Contributor Author

Tagging @jlchilders11 as we discussed this earlier.

@jlchilders11
Copy link
Contributor

I think can be productively done in a few stages,

  1. Implement the boiler plate method that spits out each test into its own file, and checks against those files
  2. Upgrade this to instead put them all into a single file. I think this has enough value proposition to be worth doing. We discussed briefly using AST, but I believe we can get most of what we would need with pytest.
$ pytest --collect-only -q
test_eggs.py::test_bacon[1]
test_eggs.py::test_bacon[2]
test_eggs.py::test_bacon[3]
test_spam.py::test_foo
test_spam.py::test_bar

no tests ran in 0.03 seconds

This would let us both check for our test names, but also make sure they live where we want them to live.

  1. Optionally, implement the crawler test for sanity checking. Alternatively, add a CI step to generate non existent tests mid CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or functionality change
Projects
None yet
Development

No branches or pull requests

2 participants