tdd

AutoMockContainer with support for automocking classes with non-interface dependencies

别说谁变了你拦得住时间么 提交于 2019-11-28 23:18:53
问题 I have a constructor which has a non-interface dependency: public MainWindowViewModel(IWorkItemProvider workItemProvider, WeekNavigatorViewModel weekNavigator) I am using the Moq.Contrib automockcontainer. If I try to automock the MainWindowViewModel class, I get an error due to the WeekNavigatorViewModel dependency. Are there any automocking containers which supports mocking of non-interface types? As Mark has shown below; yes you can! :-) I replaced the Moq.Contrib AutoMockContainer with

Unit testing factory methods which have a concrete class as a return type

别来无恙 提交于 2019-11-28 22:31:06
So I have a factory class and I'm trying to work out what the unit tests should do. From this question I could verify that the interface returned is of a particular concrete type that I would expect. What should I check for if the factory is returning concrete types (because there is no need - at the moment - for interfaces to be used)? Currently I'm doing something like the following: [Test] public void CreateSomeClassWithDependencies() { // m_factory is instantiated in the SetUp method var someClass = m_factory.CreateSomeClassWithDependencies(); Assert.IsNotNull(someClass); } The problem

AngularJS + Jasmine: Comparing objects

别说谁变了你拦得住时间么 提交于 2019-11-28 22:21:47
I'm just starting out writing tests for my AngularJS app and am doing so in Jasmine. Here are the relevant code snippets ClientController: 'use strict'; adminConsoleApp.controller('ClientController', function ClientController($scope, Client) { //Get list of clients $scope.clients = Client.query(function () { //preselect first client in array $scope.selected.client = $scope.clients[0]; }); //necessary for data-binding so that it is accessible in child scopes. $scope.selected = {}; //Current page $scope.currentPage = 'start.html'; //For Client nav bar $scope.clientNavItems = [ {destination:

Why are functional tests not enough? What do unit tests offer?

戏子无情 提交于 2019-11-28 21:34:18
问题 I just had a conversation with my lead developer who disagreed that unit tests are all that necessary or important. In his view, functional tests with a high enough code coverage should be enough since any inner refactorings (interface changes, etc.) will not lead to the tests being needed to be rewritten or looked over again. I tried explaining but didn't get very far, and thought you guys could do better. ;-) So... What are some good reasons to unit test code that functional tests don't

How do I put new List<int> {1} in an NUNIT TestCase?

跟風遠走 提交于 2019-11-28 21:08:35
I have the method: public static int Add(List<int> numbers) { if (numbers == null || numbers.Count == 0) return 0; if (numbers.Count == 1) return numbers[0]; throw new NotImplementedException(); } Here is my test against it, but it does not like new List<int> {1} in the TestCase: [TestCase(new List<int>{1}, 1)] public void Add_WithOneNumber_ReturnsNumber(List<int> numbers) { var result = CalculatorLibrary.CalculatorFunctions.Add(numbers); Assert.AreEqual(1, result); } It gives me the error: An attribute argument must be a constant expression, typeof expression or array creation expression of

Prefixing interfaces with I?

ε祈祈猫儿з 提交于 2019-11-28 21:02:16
问题 I am currently reading "Clean Code" By Rober Martin (UncleBob), and generally loving the musings of UncleBob. However, I got a bit confused, when I read that he avoids prefixing interfaces like "IPerson". He states "I don't want my users knowing that I'm handing them an interface". Thinking in TDD/injection perspective, I will always be very interested in telling the "users" of my classes that I am handing on an interface. The primary reason is that I consider Interfaces contracts between the

Is 100% code coverage a really good thing when doing unit tests? [closed]

与世无争的帅哥 提交于 2019-11-28 21:01:22
问题 I always learned that doing maximum code coverage with unit tests is good . I also hear developers from big companies such as Microsoft saying that they write more lines of testing code than the executable code itself. Now, is it really great? Doesn't it seem sometimes like a complete loss of time which has an only effect to making maintenance more difficult ? For example, let's say I have a method DisplayBooks() which populates a list of books from a database. The product requirements tell

Does TDD apply well when developing an UI?

梦想与她 提交于 2019-11-28 20:40:37
What are your opinions and experiences regarding using TDD when developing an user interface? I have been pondering about this question for some time now and just can't reach a final decision. We are about to start a Silverlight project, and I checked out the Microsoft Silverlight Unit Test Framework with TDD in mind, but I am not sure how to apply the approach to UI-development in general - or to Silverlight in particular. EDIT: The question is about if it is practical thing to use TDD for UI-development, not about how to do separation of concerns. Trying to test the exact placement of UI

How to mock a function call on a concrete object with Moq?

送分小仙女□ 提交于 2019-11-28 20:12:30
How can I do this in Moq? Foo bar = new Foo(); Fake(bar.PrivateGetter).Return('whatever value') It seems I can only find how to mock an object that was created via the framework. I want to mock just a single method/property on a concrete object I've created. In TypeMock, I would just do Isolate.WhenCalled(bar.PrivateGetter).Returns('whatever value') . Any ideas? Mark Seemann Only TypeMock Isolator (and perhaps Moles) can perform these stunts. Normal dynamic mock libraries can only mock virtual and abstract members . Ariel Popovsky You should use Moq to create your Mock object and set CallBase

How to include Rails Helpers on RSpec

谁说我不能喝 提交于 2019-11-28 20:06:44
I'm trying to include some helpers to test with rspec but no luck. What I did: created a support/helpers.rb file under my spec folder. support/helpers.rb module Helpers include ActionView::Helpers::NumberHelper include ActionView::Helpers::TextHelper end and tried to require this file in spec_helper.rb . # This file is copied to spec/ when you run 'rails generate rspec:install' require 'rubygems' require 'spork' require 'support/helpers' Spork.prefork do . . end this generates the following error: /spec/support/helpers.rb:2:in `<module:Helpers>': uninitialized constant Helpers::ActionView