3 ms·
> You need tests because you're using a dynamically typed language? I don't really understand the connection between a dynamically typed language and the need
by Syntaf 6y ago
> You need tests because you're using a dynamically typed language?
I don't really understand the connection between a dynamically typed language and the need for (or lack of) testing. Can you explain what you mean? I've never once felt like the type of language I used defined how important tests were.
When I write a unit tests, I'm not looking for syntax errors or a scenario where I'm passing the wrong type in, I'm verifying that the business rules of my domain are being properly enforced.
If your unit test is brittle, I'd say that's a pretty awful unit test. You should be isolating the component you're testing and eliminating all external dependencies like in the example below.
class ItemRecommenderGuardTest extends TestCase
{
public function setUp()
{
$dependency = Phake::mock(Dependency::class);
$this->recommenderGuard = new ItemRecommenderGuard(
$dependency
);
}
public function testGuardsInvalidItem()
{
// business rules deem this item un-recommendable. This unit
// test verifies that the guard class properly enforces these rules
$item = /* ... */;
$this->assertFalse($this->recommenderGuard->isRecommendable($item);
}
}
This test isn't brittle, and it's asserting that an item which does not meet recommendable standards is never recommendable. If someone comes along and modifies the guard class incorrectly, these unit tests are here to maintain the integrity of the system