tdd

How to refactor tests in tdd?

隐身守侯 提交于 2019-11-30 18:21:57
问题 I'm performing this TDD kata excercise: http://osherove.com/tdd-kata-1 I produced following code (points from 1 to 5 in this excercise - I have unit tests for it): public class StringCalculator { private readonly string[] _defaultSeparators = { ",", "\n" }; public int Add(string numbers) { // Parser section (string to list of ints) var separators = _defaultSeparators; var isSeparatorDefinitionSpecified = numbers.StartsWith("//"); if (isSeparatorDefinitionSpecified) { var

Android TDD: The saga continues with Robolectric & Gradle

自古美人都是妖i 提交于 2019-11-30 18:20:27
问题 Just when I'd achieved an effective development and build environment with the android-maven-plugin , the new kid on the block, Gradle, starts making inroads into the Android circles. Not being hot on Groovy and with the android-gradle plugin almost as fragmented as the OS itself I've hit some issues. Specifically around building library projects, with flavours and our buddy Robolectric . Short version I am at a loss as to what my next move should be upon encountering the gradle error; Cannot

How to detect if a mocha test is running in node.js?

落花浮王杯 提交于 2019-11-30 17:49:36
I want to make sure that in case the code is running in test mode, that it does not (accidentally) access the wrong database. What is the best way to detect if the code is currently running in test mode? As already mentioned in comment it is bad practice to build your code aware of tests. I even can't find mentioned topic on SO and even outside. However, I can think of ways to detect the fact of being launched in test. For me mocha doesn't add itself to global scope, but adds global.it . So your check may be var isInTest = typeof global.it === 'function'; I would suggest to be sure you don't

How do I use Rhino.Mocks to mock a ControllerContext

匆匆过客 提交于 2019-11-30 17:17:51
问题 I am trying to use Rhino.Mocks to mock up a ControllerContext object to gain access to runtime objects like User, Request, Response, and Session in my controller unit tests. I've written the below method in an attempt to mock up a controller. private TestController CreateTestControllerAs(string userName) { var mock = MockRepository.GenerateStub<ControllerContext>(); mock.Stub(con => con.HttpContext.User.Identity.Name).Return(userName); mock.Stub(con => con.HttpContext.Request.IsAuthenticated)

problem with rspec test, undefined method 'post'

让人想犯罪 __ 提交于 2019-11-30 17:07:03
I am writing a spec to test the behavior of the mashup_controller when someone sends a query through a URL. I need to simulate the parameters contained in the URL, and i read that the post() method will do that, however when i get an error: 1) MashupController simulates query Failure/Error: post :create NoMethodError: undefined method `post' for #<RSpec::Core::ExampleGroup::Nested_1:0x980bc50> # ./mashup_controller_rspec.rb:9:in `block (2 levels) in <top (required)>' Finished in 0.20199 seconds 1 example, 1 failure Failed examples: rspec ./mashup_controller_rspec.rb:7 # MashupController

Testing React: Target Container is not a DOM element

柔情痞子 提交于 2019-11-30 16:27:35
问题 I'm attempting to test a React component with Jest/Enzyme while using Webpack. I have a very simple test @ import React from 'react'; import { shallow } from 'enzyme'; import App from './App'; it('App', () => { const app = shallow(<App />); expect(1).toEqual(1); }); The relative component it's picking up is : import React, { Component } from 'react'; import { render } from 'react-dom'; // import './styles/normalize.css'; class App extends Component { render() { return ( <div>app</div> ); } }

Testing Chef roles and environments

人走茶凉 提交于 2019-11-30 15:05:56
问题 I'm new to Chef and have been using Test Kitchen to test the validity of my cookbooks, which works great. Now I'm trying to ensure that environment-specific attributes are correct on production nodes prior to running Chef initially. These would be defined in a role. For example, I may have recipes that converge using a Vagrant box with dev settings, which validates the cookbook. I want to be able to test that a production node's role. I think I want these tests as the source of truth

How to share state between scenarios using cucumber

戏子无情 提交于 2019-11-30 15:02:36
I have a feature "Importing articles from external website". In my first scenario I test importing a list of links from the external website. Feature: Importing articles from external website Scenario: Searching articles on example.com and return the links Given there is an Importer And its URL is "http://example.com" When we search for "demo" Then the Importer should return 25 links And one of the links should be "http://example.com/demo.html" In my steps I have the 25 links in a @result array. In my second scenario I want to take one of the links and test the fact that I parse the article

How Much Should Each Unit Test Test?

我们两清 提交于 2019-11-30 14:47:08
How much should each of my unit tests examine? For instance I have this test [TestMethod] public void IndexReturnsAView() { IActivityRepository repository = GetPopulatedRepository(); ActivityController activityController = GetActivityController(repository); ActionResult result = activityController.Index(); Assert.IsInstanceOfType(result, typeof(ViewResult)); } and also [TestMethod] public void IndexReturnsAViewWithAListOfActivitiesInModelData() { IActivityRepository repository = GetPopulatedRepository(); ActivityController activityController = GetActivityController(repository); ViewResult

RhinoMock : Mocks Vs StrictMocks Vs DynamicMocks

南笙酒味 提交于 2019-11-30 13:40:06
问题 I understand the difference between a Mock and a Stub. But different types of Mocks in RhinoMock framework confuses me. Could someone explain the concepts of Mocks Vs StrictMocks Vs DynamicMocks in terms of RhinoMock framework. your answers are greatly appreciated. 回答1: A strict mock is a mock that will throw an exception if you try to use any method that has not explicitly been set up to be used. A dynamic (or loose) mock will not throw an exception if you try to use a method that is not set