Hot answers tagged

26

Removing a public method is not "refactoring" -- refactoring is changing the implementation while continuing to pass existing tests. However, removing an unneeded method is a perfectly reasonable design change. TDD draws this out to some extent, because in reviewing the tests, you may observe that it's testing an unneeded method. The tests are driving your ...


16

Yes, of course. The easiest code to read is that which isn't there. That said, refactoring generally means improving the code without changing its behavior. If you think of something that improves the code, just do it. There's no need to fit it into some pigeon hole before you're allowed to do it.


9

In fact f() replaces all calls to b() with the exception of the unit tests that defined / described b() IMHO the typical TDD cycle will look like this: write failing tests for f() (probably based on the tests for b()): tests go red implement f() -> tests become green refactor: -> remove b() and all tests for b() For the last step, you might consider ...


5

Do you inject the target repository (i.e. are you using dependency injection) If so, you should be able to assert that _targetRepository.Add(officers) is called by querying your mocked target repository. This is a common problem and pattern for a solution in testing. Dependency injection helps you solve this since your test can provide the mocked ...


4

Yes, it is. The best, most bug-free, most readable code is the code that doesn't exist. Strive to write as much non-code as possible while fulfilling your requirements.


2

One thing to always try to remember is that we're now using CODE REPOSITORIES with VERSION CONTROL. That deleted code isn't actually gone...it's still there somewhere in a previous iteration. So blow it away! Be liberal with the delete key, because you can always go back and retrieve that precious elegant method that you thought might be useful ...


2

It's desirable to remove b() once it's no longer used, for the same reason that it's desirable not to add un-used functions in the first place. Whether you call it "readability" or something else, all else being equal it's an improvement to the code that it doesn't contain anything it has no use for. For the sake of having at least one specific measure by ...


1

Your update asks is this sufficient to test your scenario: _officerManager.UpdateHissOfficersFromConfirm(); _sourceRepository.Verify(mock => mock.GetAllActiveOfficers(), Times.Once()); _targetRepository.Verify(mock => mock.Add(It.IsAny<List<Officer>>()), Times.Once()); Ultimately it's up to you, however I wouldn't be happy with it as a ...



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