Answer the question
In order to leave comments, you need to log in
Correct approach to testing in php applications?
The documentation for PHPUnit and some articles contain code like this:
public function testMethod() {
$expectedResult = 100;
$result = $this->testclass->testMethod(1, 2);
$this->assertEquals($expectedResult, $result);
}
Answer the question
In order to leave comments, you need to log in
coverage tells about the coverage of specific rows by tests. If during the test run some lines of the source code were not affected, then coverage will be less than 100%. On average, it is considered that a good coverage is > 80%. 100% is too difficult and expensive to achieve (and not necessary).
> And if I write another 1000 of this type of tests, this will only guarantee that everything is fine on these 1000 data sets, and what if the error is just in another, 1001st set?
No one will give you guarantees. For guarantees, there is a formal verification, but this is more about mathematics than about programming. And so it is the responsibility of the programmer to test edge cases. It's okay that you missed them usually does not happen. Just if a bug occurs, then first add a test that reproduces it, and then fix it.
From the interesting:
* property-based testing https://en.wikipedia.org/wiki/QuickCheck
* bdd behat.org/en/latest/guides.html
* browser tests https://codeception.com/
* how to write tests ( concept story) https://ru.hexlet.io/blog/posts/how-to-test-code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question