tdd

Performing non-mock, state-based unit testing of non-trivial functions and their dependencies that follow CQS

核能气质少年 提交于 2020-07-31 04:57:46
问题 I realize that this question may seem to be a duplicate of questions such as this, this, this, this, and this. I'm specifically asking, however, how you would write unit tests using the Detroit style toward non-trivial code with multiple code paths. Other questions, articles, and explantations all discuss trivial examples such as a Calculator class. Further, I'm practicing CQS, or Command Query Separation, which alters the methods by which I write tests. As per Martin Fowler's article "Mocks

How to test a method that uses Random(), without arguments and return value, using JUnit or Mockito

大城市里の小女人 提交于 2020-07-09 13:19:06
问题 I'm studying to be a Java developer and right now I'm learning test driven development, which means that im very new to JUnit and Mockito. I've been struggling for a while now and I'm stuck. I have no idea how to test this particular method that has no arguments, no return value and a randomizer. Old logic: public void getPlayerToStart(int randomNr) { if (randomNr == 1) { currentPlayer = p1; opponentPlayer = p2; } else { currentPlayer = p2; opponentPlayer = p1; } } Old test @Test void

How can I effectively test against the Windows API?

ぐ巨炮叔叔 提交于 2020-07-04 06:50:23
问题 I'm still having issues justifying TDD to myself. As I have mentioned in other questions, 90% of the code I write does absolutely nothing but Call some Windows API functions and Print out the data returned from said functions. The time spent coming up with the fake data that the code needs to process under TDD is incredible -- I literally spend 5 times as much time coming up with the example data as I would spend just writing application code. Part of this problem is that often I'm