tdd

How do I have a negative scenario with Cucumber in Rails?

戏子无情 提交于 2019-12-24 10:55:39
问题 I have a negative scenario to test with Cucumber. Specifically, I want to make sure that when someone posts a URL with an invalid handle then the site returns an error. My scenario looks like: Scenario: create person with too short a handle When person named "Fred" with handle "tooshort" updates Then I should get a 500 error My step looks like When /^person named "(. )" with handle "(. )" updates$/ do |name, handle| visit "/mobile/update?handle=#{udid}&name=#{name}" When I run the scenario,

How should I register this type that has parameterized constructor, in Unity?

若如初见. 提交于 2019-12-24 10:49:50
问题 I am trying to register a type that has a constructor method like: public Foo (int myNumber, IBar bar) {...} I produce instance of IBar via Unity container. How should I regsiter and Resolve the Foo? Regarding to the example below, how can I replace the line new Foo... with a unity register and resolve way? public interface IBar { public void SayNumber(); } public class Bar : IBar { public void SayNumber() { Coonsole.Write("Number : "); } } public interface IFoo { void int GetMyNumberTimesTwo

How to exclude null value when using FsCheck Property attribute?

a 夏天 提交于 2019-12-24 08:58:46
问题 I need to write a simple method that receives a parameter (e.g. a string ) and does smth. Usually I'd end up with two tests. The first one would be a guard clause. The second would validate the expected behavior (for simplicity, the method shouldn't fail): [Fact] public void DoSmth_WithNull_Throws() { var sut = new Sut(); Assert.Throws<ArgumentNullException>(() => sut.DoSmth(null)); } [Fact] public void DoSmth_WithValidString_DoesNotThrow() { var s = "123"; var sut = new Sut(); sut.DoSmth(s);

Google Mock: Mock private variable member that is instantiated in target class's constructor

不问归期 提交于 2019-12-24 08:33:51
问题 My question is the same as Mockito: Mock private field initialization but for Google Mock framework. In a nutshell: class Target { private: Person person = new Person(); public: void testMethod() { person.someMethod(); } }; How can I mock the person instance while making unit tests for Target class? 回答1: A non-answer here: simply don't do it this way. Your problem is the call to new here. Thing is: that makes testing hard, and it also creates a very tight coupling between the Target and the

Testing ExpressJS endpoint with Jest

我是研究僧i 提交于 2019-12-24 08:25:50
问题 I'm trying to test an endpoint from my express application using Jest. I'm migrating from Mocha to try out Jest to improve the speed. However, my Jest test does not close? I'm at a loss... process.env.NODE_ENV = 'test'; const app = require('../../../index'); const request = require('supertest')(app); it('should serve the apple-app-site-association file /assetlinks.json GET', async () => { const response = await request.get('/apple-app-site-association') expect(response.statusCode).toBe(200);

Unit Test a Node.js application with Mocha, Chai, and Sinon

*爱你&永不变心* 提交于 2019-12-24 07:59:22
问题 I am new to unit testing Node.js application. My application converts CSV file to JSON after some filtering. var fs = require('fs'); var readline = require('readline'); module.exports = ((year) => { if (typeof year !== "number" || isNaN(year)){ throw new Error("Not a number"); } var rlEmitter = readline.createInterface({ input: fs.createReadStream('./datasmall.csv'), output: fs.createWriteStream('./data.json') }); rlEmitter.on('line', function(line) { /*Filter CSV line by line*/ }); rlEmitter

TDD VS BDD: REST Service

ε祈祈猫儿з 提交于 2019-12-24 07:59:06
问题 I am all confused with TDD vs BDD :) How does TDD and BDD differ in each of below point? Development: Test case first, development follows next RestService(HTTP): Don't make rest calls? If so, a) do we return only hardcoded json using a mock object? b) how to handle REST call failures? We should have test case for that too? Especially for item 2, i have googled so many articles, but couldn't find a sample (code) approach on how to handle rest calls. 回答1: BDD and TDD are not comparable to each

Automatically run specific tests on file change?

限于喜欢 提交于 2019-12-24 07:27:12
问题 I'm looking for a way to automatically run specific tests when specific files are changed, similar to what you can do with a Guardfile in Ruby on Rails . I was wondering if there is a way to do this with Laravel Elixir or with gulp (I.e. gulpfile.js ) Here is an example of what I'm looking for: watch('^app/Http/Controllers/(.+)(Controller)\.php$', function($match) { return ["tests/{$match[1]}"]; }); watch('^app/Policies/(.+)(Policy)\.php$', function($match) { return ['tests/' . str_plural(

qunit test error with equal and deepEqual

浪尽此生 提交于 2019-12-24 07:03:53
问题 I'm Trying to understand qunit testing Why is this test failing? If I compare every property, are the same ... test("Get model equal", function () { function getModel() { function myModel() { this.name = ""; this.address = ""; this.phone = ""; } return new myModel(); } var model1 = getModel(); var model2 = getModel(); equal(model1, model2); }); test("Get model deepEqual", function () { function getModel() { function myModel() { this.name = ""; this.address = ""; this.phone = ""; } return new

How to write an Android UI test where the contents of views are determined at runtime?

浪尽此生 提交于 2019-12-24 05:59:45
问题 The Situation I'm writing a timetable-viewing application and the first feature to be implemented is choosing the course for which to view the timetable. The user chooses the name of their course from a list and is taken to another screen to further specify which year, group etc. of the course they're currently in. The screens to choose your course and edit your course details are as follows: The Goal Inspired by the Google I/O 17 talk on Test-Driven Development on Android, what I wish to