tdd

Application Testing with Rails

冷暖自知 提交于 2020-01-02 13:55:47
问题 This is more of a general question and some sort of best practice discussion. How would one test a Rails application? There are mantras like BDD and TDD and frameworks like RSpec and Cucumber but how much is enough and what is the best way to go? Is it enough to use Cucumber as integration tests? Are you guys writing additional unit tests, too? So what and how is your Rails testing strategy? Looking forward to good opinions... 回答1: How would one test a Rails application? Thoroughly, aiming

How to conciliate TDD with SUT interface's contracts?

删除回忆录丶 提交于 2020-01-02 07:28:23
问题 Assuming we are implementing using TDD a Stack class, we would need, for each bit of functionality of our Stack class, to add a new test that exercises it: [TestMethod] public void Should_Be_Empty_After_Instantiation() [TestMethod] public void Should_Not_Be_Empty_After_Pushing_One_Item() ... Now, on the other hand, when doing Unit-Tests, one should focus on what external behaviour our class is supposed to provide, so the set of Unit-Tests check that all the expected contracts for my Stack

Is better to detect for exceptions and throw them or just let runtime throw them?

放肆的年华 提交于 2020-01-02 07:25:21
问题 Lets say there is setup like this: public class MyClass { public void DoSomething(string Data) { //if (String.IsNullOrWhiteSpace(Data)) //throw new NullReferenceException(); //Do something with Data and let it throw?? } } public class EntryPointClass { public void DoIt(string Data) { var logicClass = new MyClass(); try { logicClass.DoSomething(Data); } catch(Exception ex) { } } } In DoSomething I can detect a problem and throw an exception. In testing EntryPointClass I can test the expected

How do I test an abstract class's protected abstract method?

隐身守侯 提交于 2020-01-02 07:23:23
问题 I've been working on the best way to test an abstract class named TabsActionFilter . I've guranteed that classes that inherit from TabsActionFilter will have a method called GetCustomer . In practice this design seems to work well. Where I've had some issues is figuring out how to test the OnActionExecuted method of the base class. This method relies upon the implementation of the the protected abstract GetCustomer method. I've tried mocking the class using Rhino Mocks but can't seem to mock

How can I mock Server.HtmlEncode

柔情痞子 提交于 2020-01-01 12:25:09
问题 I am trying the following, but I am getting : Object reference not set to an instance of an object. HttpContextBase mockContext = MockRepository.GenerateMock<HttpContextBase>(); mockContext.Expect(c => c.Server.HtmlEncode("")).IgnoreArguments().Return(""); mockContext.Expect(c => c.Server.HtmlDecode("")).Return(""); controller.ControllerContext = new ControllerContext(mockContext, new RouteData(), controller); Matin, Thanks. That was enough to point me in the right direction provided here:

How to use Core Data for Dependency Injection

无人久伴 提交于 2020-01-01 12:10:30
问题 I'm toying with using Core Data to manage a graph of objects, mainly for dependency injection (a subset of the NSManagedObjects do need to be persisted, but that isn't the focus of my question). When running unit tests, I want to take over creation of the NSManagedObjects, replacing them with mocks. I do have a candidate means of doing this for now, which is to use the runtime's method_exchangeImplementations to exchange [NSEntityDescription insertNewObjectForEntityForName

How can I mock with a block in minitest?

北城以北 提交于 2020-01-01 12:00:21
问题 Hopefully a simple question for MiniTest folks.. I have a section of code which I'll condense into an example here: class Foo def initialize(name) @sqs = Aws::SQS::Client.new @id = @sqs.create_queue( queue_name: name ).fetch(:queue_url) @poller = Aws::SQS::QueuePoller.new(@id) end def pick_first @poller.poll(idle_timeout: 60) do |message| process_msg(message) if some_condition(message) end end How can I mock/stub/something-else so that I can feed a message through to be tested by the some

Benefits of TDD in machine learning

耗尽温柔 提交于 2020-01-01 09:27:12
问题 As far as I know typical workflow of TDD is based on black box testing. First we define interface then write one or set of test and then we implement code that pass all tests. So look at the example below: from abc import ABCMeta class InterfaceCalculator: __metaclass__ = ABCMeta @abstractmethod def calculate_mean(self): pass Exemplary test case from unittest import TestCase class TestInterfaceCalculator(TestCase): def test_should_correctly_calcluate_mean(self): X=[1,1] expected_mean = 1

Testing password length validation with RSpec

孤者浪人 提交于 2020-01-01 04:49:04
问题 I'm writing some unit tests to ensure a User model cannot have a password < 8 characters long. I started with a User model: class User < ActiveRecord::Base ... validates :password, :length =>{ :minimum => 90, :too_short => "password is too short, must be at least %{count} characters" }, :on => :create end And a user_spec.rb test: describe User do subject { FactoryGirl.build :user } its(:password) { should have_at_least(8).items } end However I realised that this doesn't actually test my

How often should we write unit tests?

别来无恙 提交于 2020-01-01 03:59:08
问题 I am recently introduced to the test-driven approach to development by my mentor at work, and he encourages me to write an unit-test whenenver "it makes sense." I understand some benefits of having a throughout unit-test suite for both regression testing and refractoring, but I do wonder how often and how throughout we should write unit-test. My mentor/development lead asks me to write a new unit test-case for a newly written control flow in a method that is already being tested by the