I'm studying and studying practice-driven development. I am doing very well, because it is very straightforward till now but I have some questions like some sections below should be examined.
publicPublic testPersonEnrollmentDateIsSet () {// Simplicity I get PDO / connection $ PDO = $ this- & gt; GetPDOMock () has fun; $ PDOStatement = $ this- & gt; GetPDOStatementMock (); $ PDO- & gt; Method ('Ready') - & gt; WillReturn ($ PDOStatement); $ PDOStatement-> Method ('fetch') - & gt; WillReturn ('2000/01/01'); $ AccountMaster = $ this- & gt; Mapfiber-> Build ('AccountMan', array ($ PDO)); $ Person = $ this- & gt; Unit factory-> Build ('person'); $ Account = $ this- & gt; Unit factory-> Build ('Account'); $ Person & gt; SetAccount ($ account); $ AccountMapper- & gt; GetAccountEnrollmentDate ($ person); $ This- & gt; Emphasis Acklers ('2001-01-01', $ person- & gt; getAccountEnrollmentDate ()); }
I am a little uncertain if I should also test it for two reasons.
Unit Test Logic
The above examples I am testing if the value is mapped correctly. Just logic, there is no database in the joke of the connection. This is horrible because I can run a test of business logic without any other developers to install or configure database dependencies.
DBUnit test results
However, there may be a different configuration that runs on demand to test SQL queries, which is another type of test completely while the unit tests The SQL Test is also strengthened to make different runs from
The test will be exactly the same as PDO
can not be done except for the connection and the actual database connection will not be
the cause of concern
I was torn because it is testing for various things, it is essentially a duplicate code.
If I get rid of the unit test, I introduce a required database dependency at all times. As the codebase grows, testing over time will slow down, no out-of-the-box tests will be done;
If I get rid of database testing, then I will not assure that SQL will return the expected information.
My questions are:
Is this a valid reason to keep both tests?
Is it worth it or is it possible that this maintenance can be a nightmare? According to your comments, it seems that you want to test what PDO is doing. (What is ready
, execute
etc ... being called properly and I work with them)?
It is not like what you want to do here, with unit testing, you do not want to test PDO or any other library, and you do not have to test the argument or behavior of the PDO. Ensure that these things have been done by people in charge of PDO.
The test you want to perform is the correct execution of your code and therefore you want to test the code of your code, getAccountExpirationDate
, and therefore the results you expect from. No expected results from PDO calls
So, and if I think your code is right, all you have to do is check that you give the expiry date of $ person
as the parameter $ result
with the expected value - if you do not use the PDO properly, the test will fail!
A correct test can be done
- Create a
usermasters
object and open a DB transaction - Enter data in DB
$ result
-
person
object to get the desired code correcttaxId
andclientID
- Run
UserMapper-> getAccountExpirationDate ($ person)
- Assurance with your query
$ result
- Run
-
can do; Date format, etc ...
If you are going to test such things in many tests, then set up
and tyredown
and after each test roll your DB back.
No comments:
Post a Comment