jeudi 15 novembre 2018

How to avoid reimplementing logic in property based testing?

I'm reading about property based testing and I'm wondering how can I test this code using that paradigm.

class Invoice {

    private final String id;
    private final String companyName;

    public String name() {
        return id + "_" + removeDots(companyName.trim());
    }

}

I want to test Invoice::name method, so I would do something like this:

class InvoiceTest {

    //Let's say 'id' and 'companyName' are random auto-generated values
    //by some framework
    @Test 
    public void nameTest(String id, String companyName) {
        Invoice invoice = new Invoice(id, companyName);
        assertThat(invoice.name()).isEqualTo(id + "_" + removeDots(companyName.trim()));
    }

}

As you see, it makes no sense. I'm reimplementing the logic in the test method. Maybe, is property based testing suitable only for "mathematical" logic?

Aucun commentaire:

Enregistrer un commentaire