tdd

Best Option for Retrospective application of TDD into C# codebase

白昼怎懂夜的黑 提交于 2019-12-07 06:05:41
问题 I have an existing framework consisting of 5 C# libraries, the framework is well used since 2006 and is the main code base to the majority of my projects. My company wishes to roll out TDD for reasons of software quality; having worked through many tutorials and reading the theory I understand the benefits of TDD. Time is not unlimited I need to make plans for a pragmatic approach to this. From what I know already, the options as I see them are: A) One test project could be used in order to

How to handle the refactoring phase of TDD

自作多情 提交于 2019-12-07 04:47:08
问题 In the course of a TDD session, suppose I write a failing test, and then make it pass. I refactor by extracting code out of the original Unit, using refactorings such as Extract Class and Move Method. Now further suppose that my original test no longer covers the extracted code because the original code now mocks out its dependencies, as is correct for a Unit test. Is it proper to go back and retrofit tests onto the extracted code? Or did I make a mistake in how I ended up with untested code

Testing smart wrappers for 3rd party libraries

元气小坏坏 提交于 2019-12-07 03:25:06
问题 Suppose you are required to use an unnecessarily complicated, difficult to mock (perhaps it has concrete classes with no virtual interface), and unreliable third-party library that integrates with some external resource such as a socket or a database. You decide to create "wrapper" interfaces/classes to greatly simplify the usage of this library and to allow developers using the wrapper to continue to write testable code. The wrapper's interface looks nothing like the original interface. I

Python TDD directory structure

浪尽此生 提交于 2019-12-07 03:09:31
问题 Is there a particular directory structure used for TDD in Python? Tutorials talk about the content of the tests, but not where to place them From poking around Python Koans, suspect its something like: /project/main_program.py # This has main method, starts program /project/classes/<many classes>.py /project/main_test.py # This simply directs unittest onto tests, can use parameters fed to it to customise tests for environment /project/tests/<many tests>.py # to run tests, type "python -m

What is the purpose of unit testing an interface repository

南楼画角 提交于 2019-12-07 02:17:02
问题 I am unit testing an ICustomerRepository interface used for retrieving objects of type Customer . As a unit test what value am I gaining by testing the ICustomerRepository in this manner? Under what conditions would the below test fail? For tests of this nature is it advisable to do tests that I know should fail? i.e. look for id 4 when I know I've only placed 5 in the repository I am probably missing something obvious but it seems the integration tests of the class that implements

TDD: Help with writing Testable Class

强颜欢笑 提交于 2019-12-07 02:07:31
问题 I have a quick little application and wanted to give a try to develop using TDD. I've never used TDD and actually didn't even know what it was until I found ASP.NET-MVC. (My first MVC app had unit tests, but they were brittle, way coupled, took too much up keep, and were abandoned -- I've come to learn unit tests != TDD). Background on app: I have a text dump of a purchase order read in as a string. I need to parse the text and return new purchase order number, new line item number, old

Nock is not intercepting API call in Redux test

橙三吉。 提交于 2019-12-07 00:33:08
问题 I'm trying to test an api call in a redux app. The code pretty much follows the pattern outlined in the Async Action Creators section of the redux docs: http://redux.js.org/docs/recipes/WritingTests.html The gist of it is that you use redux-mock-store to record and assert against any actions that are triggered. This is the whole test, using nock to mock the api call: import React from 'React' import ReactDOM from 'react-dom' import expect from 'expect'; import expectJSX from 'expect-jsx';

Test Cases VS ASSERTION statement

蹲街弑〆低调 提交于 2019-12-06 21:57:54
问题 In my most C++ project I heavily used ASSERTION statement as following: int doWonderfulThings(const int* fantasticData) { ASSERT(fantasticData); if(!fantasticData) return -1; // ,,, return WOW_VALUE; } But TDD community seems like to enjoy doing something like this: int doMoreWonderfulThings(const int* fantasticData) { if(!fantasticData) return ERROR_VALUE; // ... return AHA_VALUE; } TEST(TDD_Enjoy) { ASSERT_EQ(ERROR_VALUE, doMoreWonderfulThings(0L)); ASSERT_EQ(AHA_VALUE,

Arrange Act Assert Alternatives

谁都会走 提交于 2019-12-06 20:44:27
问题 The general question is are there alternative patterns to AAA for unit testing ? If, yes, would be very interesting to see some examples and hear about their pros and cons. And as the simplest example of AAA test (in c#, using var for the sake of simplicity): // Arranging var annualSalary = 120000M; var period = 3; // for a quarter profit var calc = new SalaryCalculator(); // Acting var result = calc.CalculateProfit(annualSalary, period); // Assertion Assert.IsEqual(40000, result); 回答1: I

Mocking DbContext for TDD Repository

孤街醉人 提交于 2019-12-06 19:34:36
Trying to Mock my EF Context which is coupled to my Repository. Im using Moq, trying to setup a mocked Context and pass it into the Repository by the constructor. After that Im calling the Add method, to simply add a new object which I after that try to Assert by checking if the context i passed in has changed state... Error Im getting is a NullReference Exception and I guess its because my mocking isn't correct.. This is the code: Test with not working mock [TestClass] public class GameRepositoryTests { [TestMethod] public void PlayerThatWonMustBeAddedToTopList() { // Arrange var expected =