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

Use "Faker" package in tests #69

Open
simon-liebehenschel opened this issue May 14, 2022 · 2 comments
Open

Use "Faker" package in tests #69

simon-liebehenschel opened this issue May 14, 2022 · 2 comments

Comments

@simon-liebehenschel
Copy link

simon-liebehenschel commented May 14, 2022

https://faker.readthedocs.io/en/master/

It is not a good idea to hard-code manually some specific values for every test. The first problem is that it is a manual redundant work. The second problem is that your test works for "foobar" input, but you do not know whether it will work a "spameggs" or "abcdef" string.

Bad

def test_do_something():
    do_something("foo bar")  # Poor test coverage

Good

def test_do_something(faker: Faker):
    do_something(faker.str())

Good too

def test_do_something(faker: Faker):
    do_something("foo bar")  # It is critical to check exactly this input 
    do_something(faker.str())

A general rule is to hard-code input values only when these specific values must be tested. E.g. it is fine to hard-code "foo bar" input for your test if you have a feeling that the test may fail for the value and it is critical to cover it.

I am using Faker somewhere for 1-2 years and I am fine with it.
There is also another package https://hypothesis.readthedocs.io/en/latest/ which looks very promising, but I have no experience with it.

@Krukov What is your opinion on this?

@Krukov
Copy link
Owner

Krukov commented May 14, 2022

Hello, yes you absolutely right. No doubts that tests not so perfect in this project.
I also had been using faker long time ago ( then something goes wrong with me ), and yes it a great tool to gen random data for tests. About hypothesis - I think that is more complicated solution and more about testing boundary values( that is my point of view).

@Krukov
Copy link
Owner

Krukov commented May 18, 2022

I have added hypothesis - because there was a good case for it https://github.com/Krukov/cashews/pull/76/files

@Krukov Krukov closed this as completed May 18, 2022
@Krukov Krukov reopened this May 18, 2022
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

2 participants