Fork me on GitHub
#ldnclj
<
2016-02-01
>
glenjamin09:02:56

Morning, anyone know of a good example of using property-based testing for validation?

glenjamin09:02:35

Say I have a text field that's 1-50 alphanumeric chars, asserting the positive is simple enough - but what properties would you apply for failure cases?

glenjamin09:02:41

Or do I just generate strings and have an if statement in the property?

paulspencerwilliams10:02:40

@glenjamin: good question. My current (limited) understanding of property based testing is exactly that. Have a property like ‘allows only valid inputs’ and throws strings from 0 - 5000 character strings at it. the property passes if the string was valid and the system allows access, or if an invalid string results in matching error message?

paulspencerwilliams10:02:06

@glenjamin: have you done my property based testing?

glenjamin10:02:08

i’ve used it a bit, mostly to try and do this type of testing

glenjamin10:02:20

the problem is how best to know whether a string is valid or not, since that’s exactly what i’m testing

paulspencerwilliams10:02:58

should the story / requirements not specify what should and shouldn’t be valid rather than the system under test?

glenjamin10:02:37

yup, the bit i’m struggling with is how to express those in a property-based system

paulspencerwilliams10:02:36

I’m insufficiently experienced to offer advice about it, having only read and played this weekend. I did have a v. useful conversation in #C08LK2DH7 about it, and received excellent advise. I would be keen to follow your endeavours, and assist where I can.

agile_geek10:02:58

We all seem to be struggling with how to turn a spec into property based testing assertions.

agile_geek10:02:45

My personal experiments around this 5-6 months ago led me to deduce it was much harder to write the code to generate and verify the test properties than the code to implement the solution. This was probably because it was too trivial a problem.

agile_geek10:02:38

I ended up testing invariants like inverting the inputs and outputs with property based testing and the rest of the tests as normal example based.

agile_geek10:02:15

My problem was a 'cheque parser' i.e. a number to words convertor that takes a number and expresses it in english words. e.g 120456 = "one hundred and twenty thousand, four hundred and fifty six"

agile_geek10:02:52

I found property based testing unhelpful here and what few tests I wrote took me much longer than the implementation and were so complex I wanted tests around them to prove the property tests were correct!

agile_geek10:02:38

We should start a virtual property based testing self help group 😉

glenjamin11:02:10

part of my problem (i think), is that validation rules combine via intersection

glenjamin11:02:19

but the inverse combines via union

glenjamin11:02:00

so if my rules are 1-20 chars, alphanum. my inverse properties are <1, >20, non-alphanum

agile_geek11:02:32

@glenjamin: hadn't thought of that but nice deduction. I think that's true of a lot of problems, if not all?

annapawlicka21:02:03

@maleghast: the company that I work for is hiring and they do offer H1B: https://news.ycombinator.com/item?id=11012931

thomas21:02:32

@annapawlicka: what is it like working for W?

annapawlicka21:02:49

Yup. Good team and interesting problems to solve.

thomas21:02:22

and how is life out there?

annapawlicka21:02:52

more laid back than in London simple_smile

thomas21:02:49

must be all those hippies in SF 😉

annapawlicka21:02:25

haha very likely

thomas21:02:47

but good to hear that you are enjoying yourself!!! and also great of you to drop in on lndclj!

annapawlicka21:02:51

I never left lndclj simple_smile the problem is the time difference. Everyone is asleep when I’m online