Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it good practice to unit test properties?

Tags:

unit-testing

I'm still getting to grips with the whole TDD concept. Should I be writing tests for properties? Should one only write tests on properties containing sufficient logic? Any thoughts or examples on this would be great.

like image 379
hoakey Avatar asked Dec 08 '22 00:12

hoakey


2 Answers

Writing a test for public getter of a private field will not give you much if this getter does nothing except returning your private field. But if it does contain some logic (or just something that can fail, like converting your private Int32 field to Byte), testing such property starts to make sense.

like image 120
Piotr Justyna Avatar answered Feb 27 '23 21:02

Piotr Justyna


Test things that have a reasonable chance of failure - you gain no extra confidence by testing properties with no logic beyond get/set.

like image 32
orip Avatar answered Feb 27 '23 21:02

orip