Tagged Questions
5
votes
2answers
489 views
Event Driven Programming: A sequence of unfortunate events
I have a very basic game loop whose primary purpose is to check for updates & changes to a list.
I have contemplated using event driven programming to replace the game loop/list idea with an ...
6
votes
3answers
533 views
Mocking concrete class - Not recommended
I've just read an excerpt of "Growing Object-Oriented Software" book which explains some reasons why mocking concrete class is not recommended.
Here some sample code of a unit-test for the ...
12
votes
5answers
557 views
What is considered third party code?
Inspired by this question Using third-party libraries - always use a wrapper?
I wanted to know what people actually consider as third-party libraries.
Example from PHP:
If I'm building an application ...
4
votes
1answer
284 views
Is wrapping a third party code the only solution to unit test its consumers?
I'm doing unit testing and in one of my classes I need to send a mail from one of the methods, so using constructor injection I inject an instance of Zend_Mail class which is in Zend framework.
Now ...
5
votes
4answers
278 views
Are injectable classes allowed to have constructor parameters in DI?
Given the following code:
class ClientClass{
public function print(){
//some code to calculate $inputString
$parser= new Parser($inputString);
$result= ...
17
votes
4answers
748 views
Do unit tests sometimes break encapsulation?
I very often hear the following: "If you want to test private methods, you'd better put that in another class and expose it."
While sometimes that's the case and we have a hiding concept inside our ...
4
votes
4answers
146 views
How to implement isValid correctly?
I'm trying to provide a mechanism for validating my object like this:
class SomeObject {
private $_inputString;
private $_errors=array();
public function __construct($inputString) {
...
7
votes
3answers
377 views
Unit testing time-bound code
I'm currently working on an application that does a lot of time-bound operations. That is, based on long now = System.currentTimeMillis();, and combined with an scheduler, it will calculate periods of ...
8
votes
5answers
855 views
Is unit testing procedural code effective?
On a current project, the powers that be want to have unit testing incorporated into our development cycle to avoid the constant amount of bugs that seem to seep into our code. The problem is that the ...
8
votes
9answers
1k views
Should I pass an object into a constructor, or instantiate in class?
Consider these two examples:
Passing an object to a constructor
class ExampleA
{
private $config;
public function __construct($config)
{
$this->config = $config;
}
}
$config = new ...
3
votes
1answer
62 views
Test interface implementation
I have a interface in our code base that I would like to be able to mock out for unit testing. I am writing a test implementation to allow the individual tests to be able to override the specific ...
6
votes
8answers
274 views
What benefit do I get from good methodology?
One of my friends has worked for nearly 10 years, asked me why he needs to learn new things such as unit-testing, MVC, Multi-tier architecture (he creates 3-tier application but designs like 2-tier), ...
6
votes
2answers
422 views
OOP for unit testing : The good, the bad and the ugly
I have recently read Miško Hevery's pdf guide to writing testable code in which its stated that you should limit your classes instanciations in your constructors. I understand that its what you should ...
11
votes
6answers
2k views
Convert from Procedural to Object Oriented Code
I have been reading Working Effectively with Legacy Code and Clean Code with the goal of learning strategies on how to begin cleaning up the existing code-base of a large ASP.NET webforms application.
...
7
votes
4answers
305 views
Staying OO and Testable while working with a database
What are some OOP strategies for working with a database but keeping things unit testable? Say I have a User class and my production environment works against MySQL. I see a couple possible ...
