6
votes
3answers
342 views

Are “Stocks” a TDD/Unit testing anti pattern?

From Martin Fowler's Mocks Aren't Stubs he states that Stubs provide canned answers to calls made during the test while Mocks objects pre-programmed with expectations which form a specification of the ...
37
votes
9answers
3k views

Do we need Logging when doing TDD?

When doing the Red, Green & Refactor cycle we should always write the minimum code to pass the test. This is the way I have been taught about TDD and the way almost all books describe the process. ...
1
vote
3answers
318 views

Does non-virtual-by-default lead us to composition-over-inheritance?

There are some design guidelines about testable code in “The Art of Unit Testing”. The first one is “Make methods virtual by default”. I’m curious to know your idea about non-virtual-by-default ...
1
vote
1answer
596 views

Should we mock entities and value objects when doing DDD?

After reading a few articles about Newable vs Injectable objects and how these concepts relate to DDD's services, entities and value objects, I was left with some doubts about using newables in my ...
0
votes
3answers
158 views

What concept am I missing with private methods and testing? [duplicate]

I've read a lot o blogs arguing about private methods and testing. Some people say you should not test private methods, they say you should make them public or put those methods in a new class. But ...
5
votes
2answers
1k 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 ...
8
votes
3answers
819 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 ...
15
votes
5answers
1k 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 ...
5
votes
1answer
483 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 ...
4
votes
4answers
322 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= ...
21
votes
5answers
1k views

Do unit tests sometimes break encapsulation? [duplicate]

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
171 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
474 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 ...
9
votes
5answers
1k 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
79 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
325 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
567 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. ...
8
votes
4answers
377 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 ...