Tag Info

Hot answers tagged

8

Writing testable code is important if you want to be able to prove that your code actually works. I tend to agree with the negative sentiments about warping your code into heinous contortions just to fit it to a particular test framework. On the other hand, everybody here has, at some point or other, had to deal with that 1,000 line long magic function ...


4

To me, though, it seems like overkill to pass in the time as an argument. You're right, and with mocking you can make the code testable and avoid passing the time (pun intention undefined). Example code: def time_of_day(): return datetime.datetime.utcnow().strftime('%H:%M:%S') Now let's say you want to test what happens during a leap second. As ...


4

From my experience, one of the most important and most far-reaching decisions you make when building a program is how you break the code down into units (where "units" is used in its broadest sense). If you are using a class-based OO language, you need to break all the internal mechanisms used to implement the program into some number of classes. Then you ...


3

@CarlManaster has the right idea: It's the responsibility of the developer to: write a unit test, verify that it fails, implement it, verify that it succeeds, refactor the feature without failing the test, and finally refactor the test code for every feature. The reason for each of these can be summarised as follows: Writing the test before the code ...


1

Behat is at its best when used a Behaviour Driven Development tool. Try to think of your feature files as requirements, not tests. Change the requirements first, then alter your system to get the tests passing! To answer specifically your question about languages, if you do have a multi-language site, try putting an extra step like 'Given I'm an Englishman' ...


1

Directly testing your own code is good form, and a system that encourages someone other than the developer to test it is a hazard, as the code may not even be testable without heavy modifications. That said, expanding a project's unit test suite is a great way to get yourself on board with now it works. TDD style test first coding works very well in a ...


1

Remember many rules in programming are essentially recommendations you can follow. So sometimes this is acceptable. Unit tests are called that way because they focus on testing single units of work. Generally, if you need more than one assertion per test case, you are structuring your test inappropriately. testing alternative code flows in the method, ...


1

A unit test should test the job that the tested unit has, no more, no less. If your method has the job of acessing the database and issuing UPDATE and INSERT commands as required, then that is what you have to test. When your collaborator is a data base, then issuing SQL is not an implementation detail: it is the behaviour of that unit. Compared to the ...



Only top voted, non community-wiki answers of a minimum length are eligible