tdd

As a “mockist” TDD practitioner, should I mock other methods in the same class as the method under test?

跟風遠走 提交于 2019-12-19 17:06:34
问题 After reading Martin Fowler's Mocks Aren't Stubs, I've discovered I've been practicing TDD in the "mockist" fashion. But I'm wondering if even in mockist TDD if one can take mocking too far. Here's an updated example in Python-style pseudo-code: def sync_path(self): if self.confirm_or_create_connection(): self.sync(self.dirpath) The confirm_or_create_connection() method creates a connection to a server. I tested a method similar to this in two tests, both of which mock confirm_or_create

As a “mockist” TDD practitioner, should I mock other methods in the same class as the method under test?

流过昼夜 提交于 2019-12-19 17:05:49
问题 After reading Martin Fowler's Mocks Aren't Stubs, I've discovered I've been practicing TDD in the "mockist" fashion. But I'm wondering if even in mockist TDD if one can take mocking too far. Here's an updated example in Python-style pseudo-code: def sync_path(self): if self.confirm_or_create_connection(): self.sync(self.dirpath) The confirm_or_create_connection() method creates a connection to a server. I tested a method similar to this in two tests, both of which mock confirm_or_create

Check several different example inputs in a single test?

二次信任 提交于 2019-12-19 13:50:09
问题 Let's say I want to write a function that validates an email address with a regex. I write a little test to check my function and write the actual function. Make it pass. However, I can come up with a bunch of different ways to test the same function (test@test.com; test234@test.com; test.test.com, etc). Do I put all the incantations that I need to check in the same, single test with several ASSERTS or do I write a new test for every single thing I can think of? Thanks! 回答1: Most testing

How should I compare each element values in two lists?

雨燕双飞 提交于 2019-12-19 12:22:45
问题 In my unit test method, I am having two list. One is the expectedValueList and other is actualvalueList . expectedValueList={a=1,b=2,c=3,d=4} actualvalueList={d=4,b=2,c=3,a=1} I am comparing only one element by doing this CollectionAssert.AreEqual(expectedValueList.Select(x => x.a).ToList() ,actualvalueList.Select(x => x.a).ToList()) how to compare remaining elements ? 回答1: You can use SequenceEqual if they are already in order directly expectedValueList.SequenceEqual(actualvalueList); if

How should I compare each element values in two lists?

左心房为你撑大大i 提交于 2019-12-19 12:22:13
问题 In my unit test method, I am having two list. One is the expectedValueList and other is actualvalueList . expectedValueList={a=1,b=2,c=3,d=4} actualvalueList={d=4,b=2,c=3,a=1} I am comparing only one element by doing this CollectionAssert.AreEqual(expectedValueList.Select(x => x.a).ToList() ,actualvalueList.Select(x => x.a).ToList()) how to compare remaining elements ? 回答1: You can use SequenceEqual if they are already in order directly expectedValueList.SequenceEqual(actualvalueList); if

Test drive Hystrix Circuit Breaker configuration

允我心安 提交于 2019-12-19 11:39:09
问题 Our application is written in anit-fragile manner by implementing circuit breaker pattern using Hystrix. The whole of the application is created using test driven practice but is stuck at the point where we need to implement the circuit breaker strategy by configuring the same on the methods. Below is the sample configuration used by us - @HystrixCommand(commandProperties = { @HystrixProperty(name = "circuitBreaker.enabled", value = "true"), @HystrixProperty(name = "circuitBreaker

How to mock static method in Java?

余生长醉 提交于 2019-12-19 08:54:57
问题 I have a class FileGenerator , and I'm writing a test for the generateFile() method that should do the following: 1) it should call the static method getBlockImpl(FileTypeEnum) on BlockAbstractFactory 2) it should populate variable blockList from the subclass method getBlocks() 3) it should call a static method createFile from a final helper class FileHelper passing a String parameter 4) it should call the run method of each BlockController in the blockList So far, I have this empty method:

Unit testing value objects in isolation from its dependencies

淺唱寂寞╮ 提交于 2019-12-19 08:50:45
问题 TL;DR How do you test a value object in isolation from its dependencies without stubbing or injecting them? In Misko Hevery's blog post To “new” or not to “new”… he advocates the following (quoted from the blog post): An Injectable class can ask for other Injectables in its constructor.(Sometimes I refer to Injectables as Service Objects, but that term is overloaded.). Injectable can never ask for a non-Injectable (Newable) in its constructor. Newables can ask for other Newables in their

railstutorial.org, Chapter 6. unknown attribute: password

一笑奈何 提交于 2019-12-19 03:14:15
问题 I have finished Chapter 6 of railstutorial but all my User model specs have started failing soon after I added password & password_confirmation with the following errors: Failures: 1) User Failure/Error: @user = User.new(name: "Example User", email: "user@example.com", ActiveRecord::UnknownAttributeError: unknown attribute: password # ./spec/models/user_spec.rb:17:in `new' # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>' 2) User Failure/Error: @user = User.new(name:

railstutorial.org, Chapter 6. unknown attribute: password

≯℡__Kan透↙ 提交于 2019-12-19 03:14:08
问题 I have finished Chapter 6 of railstutorial but all my User model specs have started failing soon after I added password & password_confirmation with the following errors: Failures: 1) User Failure/Error: @user = User.new(name: "Example User", email: "user@example.com", ActiveRecord::UnknownAttributeError: unknown attribute: password # ./spec/models/user_spec.rb:17:in `new' # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>' 2) User Failure/Error: @user = User.new(name: