tdd

Faking an enumerator in FakeItEasy

跟風遠走 提交于 2019-12-10 18:54:32
问题 How can I create a fake with FakeItEasy that allows different return values on successive calls. This is one example of what I would like to be able to do: var enumerator = A.Fake<IDictionaryEnumerator>(); A.CallTo(() => enumerator.MoveNext()).Returns(true); //Expected value for first call A.CallTo(() => enumerator.Key).Returns("key1"); A.CallTo(() => enumerator.Value).Returns("value1"); A.CallTo(() => enumerator.MoveNext()).Returns(false); //Expected value for second call Assert.IsTrue

How do you go about splitting a class with TDD?

瘦欲@ 提交于 2019-12-10 18:46:06
问题 I feel pretty skilled in TDD, and I'm even consired the "TDD expert" in my company, but nevertheless, there are some cases that I feel I don't know how to handle properly, so I would like to hear other's opinions. My problems is as follows: Even though in general TDD helps me think of the core responsibility of a class, and extract every other responsibility to dependent classes, there are cases that after some time I realize that one of the classes has multiple responsibilities and it needs

unit testing philosophy

假装没事ソ 提交于 2019-12-10 18:18:40
问题 I have a "recipe" method which i am trying to write using TDD. It basically calls out to different methods and occasionally makes decisions based on results of these methods: public void HandleNewData(Data data) { var existingDataStore = dataProvider.Find(data.ID); if (data == null) return; UpdateDataStore(existingDataStore, data, CurrentDateTime); NotifyReceivedData(data); if (!dataValidator.Validate(data)) return; //... more operations similar to above } My knee jerk reaction would be to

Test Driven Development - Should I test database columns and indexes?

怎甘沉沦 提交于 2019-12-10 17:55:59
问题 I am new to TDD. I find that the shoulda gem has the ability to test if a column exists for a database entity as well as the ability to test its indexes. But is it necessary to include testing of columns and indexes in my test suite? Will I need to be concerned with a potential deletion of any of the columns and indexes during development? 回答1: Don't test database columns ; that's just testing implementation. Don't test implementation, test behavior. Do test functionality that uses the

NUnit best practice

a 夏天 提交于 2019-12-10 16:36:07
问题 Environment: (C# WinForms application in Visual Studio Professional 2008) I've been digging around a little for guidance on NUnit best practices. As a solo programmer working in a relatively isolated environment I'm hoping that collective wisdom here can help me. Scott White has a few good starting points here but I'm not sure I totally agree with everything he's said -- particularly point 2. My instincts tell me that the closer a test is to the code being tested the more likely you are to

Unit Testing practice with Linq to SQL

允我心安 提交于 2019-12-10 15:57:12
问题 I'm trying to wrap my head around unit testing, and I've encountered a behavior that I'm unsure of: "Can Backup Inventory" Basically, the "Inventory" table is copied to the "InventoryHistory" table, and given a time-stamp of when the backup occurred ("HistoryDate"). Here's the code for backing-up inventory: DateTime historyDate = DateTime.Now; MyDataContext db = new MyDataContext(); db.GetTable<InventoryHistory>().InsertAllOnSubmit( db.GetTable<Inventory>() .Select(i => new InventoryHistory {

Dapper: Unit Testing SQL Queries

大兔子大兔子 提交于 2019-12-10 15:52:44
问题 I am starting with Dapper, the micro-ORM, and i use the Dapper Rainbow. I want to test the queries and the data retrieved by them. I mean, for example, i have the UserService with the method GetAll() , and i want to test that the sql query is retrieving all the users from some List (not from the database because i want the tests to be fast). Do you know how can i do that? My service class (and the method i want to test): public static class UserService{ public static IEnumerable<User> GetAll(

moq callbase for methods that do not return value (void methods)

六月ゝ 毕业季﹏ 提交于 2019-12-10 15:11:02
问题 I am trying to mock my class that is under test, so that I can callbase on individual methods when testing them. This will allow me to test the method setup as callbase only, and all other methods (of the same class) called from within the test method will be mocked. However, I am unable to do this for the methods that do not return a value. The intellisense just doesn't display the option of callbase, for methods that do not return value. Is this possible? The Service Class: public class

How to make junit testing to stop after first failing test

霸气de小男生 提交于 2019-12-10 14:53:58
问题 Is there a way to make running junit test to stop after a test fails? 回答1: Yes ... this ability (or the lack of it) is built into the various TestRunners (Console, AWT, Swing, Ant, Maven or the one built into Eclipse, etc). You'll have to look for this control in the documentation for the specific platform you're using. 回答2: I know that in Ant, the junit task has options "haltonerror" and "haltonfailure" that controls this behavior. 来源: https://stackoverflow.com/questions/188606/how-to-make

How to mock Net::HTTP::Post?

百般思念 提交于 2019-12-10 14:29:49
问题 Yes, I know it is best to use webmock, but I would like to know how to mock this method in RSpec: def method_to_test url = URI.parse uri req = Net::HTTP::Post.new url.path res = Net::HTTP.start(url.host, url.port) do |http| http.request req, foo: 1 end res end Here is the RSpec: let( :uri ) { 'http://example.com' } specify 'HTTP call' do http = mock :http Net::HTTP.stub!(:start).and_yield http http.should_receive(:request).with(Net::HTTP::Post.new(uri), foo: 1) .and_return 202 method_to_test