bdd

How (strategy) to unit test properties (get/set) in BDD style?

孤街浪徒 提交于 2019-12-10 17:52:38
问题 I have a class (of many) that have properties. Some have logic in them and some don't. Assuming I want to test these properties, how do I go about doing that? Recently, I've been interested in BDD style for creating unit tests. see here and here. So I'd do a setup of the context - basically create the SUT and load up whatever is needed. Then in each Observation (test method), I'd verify that a particular property contains what it should contain. Here's my question. If the SUT has 20

When to switch from cucumber to rspec in the BDD cycle for a login procedure

丶灬走出姿态 提交于 2019-12-10 17:47:53
问题 I'm still trying to understand the combination of cucumber and rspec in the BDD cycle. I have defined the following scenarios for a very simple login system: Feature: Log in In order to get access to the application As a user I want to log in Scenario: User logs in successfully Given I exist as a user When I go to the login page And I fill in "username" with "gabrielhilal" And I fill in "password" with "secret" And I press "Login" Then I should see "Welcome gabrielhilal" And I should be

How to create stub for ajax function using Jasmine BDD

与世无争的帅哥 提交于 2019-12-10 16:51:34
问题 I'm struggling to find any examples on how to fake an ajax call using Jasmine BDD? I have a custom ajax function that works like so... ajax({ url: 'JSON.php', dataType: 'json', onSuccess: function(resp) { console.log(resp); } }); ...and I've no idea how to create a stub to fake calling the actual ajax function. I want to avoid calling the ajax function as it could slow down my test suite if a real ajax call to the server takes some time to respond and I've loads of specs in my test suite. I

selenium.click() doesn't work: Argument 1 of EventTarget.dispatchEvent does not implement interface Event

旧街凉风 提交于 2019-12-10 16:29:36
问题 I have the next problem: I try to run a simple click with DefaultSelenium object just like this: private DefaultSelenium seleniumClient = new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost:8080"); @When("^I try to login with user \"([^\"]*)\" and password \"([^\"]*)\"$") public void I_try_to_login_with_user_and_password(String userName, String password) throws Throwable { enterData("id=username", userName); enterData("id=password",password); seleniumClient.click("id=login");

MSpec: How to make static variables thread-safe?

拈花ヽ惹草 提交于 2019-12-10 15:20:57
问题 I'm using MSpec for my latest project, and overall I'm really happy with it. However, I do have an issue with concurrency when my tests run in paralel and I'm wondering if anybody has run into this issue or, even better, has a solution? MSpec heavily relies on static methods and variables to work. Now it appears when I define static variables in my base classes, that are used by multiple test classes, and I run my tests in paralel, that they share the same static variables and thus interfere

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

Behat hangs when there are multiple scenarios, but works on a single one

懵懂的女人 提交于 2019-12-10 14:10:20
问题 I have Behat test cases written like so: Feature: Checkout In order to buy products As a customer I need to be able to checkout items in the cart Background: Given step 1 And step 2 @Ready Scenario: Deliver now When step 3 Then step 4 @NoneReady Scenario: Deliver later When step a Then step b And step c @AddressNotCovered Scenario: Address Not Covered When step i Then step ii If I run behat on a single tag, it works just fine: $ behat --tags=Ready Feature: Checkout In order to buy products As

jasmine.js expect() does not work inside an asynchronous callback

匆匆过客 提交于 2019-12-10 12:30:02
问题 I'm getting acquainted with Jasmine (http://pivotal.github.com/jasmine/) and found something rather baffling: it("should be able to send a Ghost Request", function() { var api = fm.api_wrapper; api.sendGhostRequest(function(response) { console.dir('server says: ', response); }); expect(true).toEqual(false); }); Fails as expected. However, moving the expect call inside the callback: it("should be able to send a Ghost Request", function() { var api = fm.api_wrapper; api.sendGhostRequest

Given-When-Then scenarios for Webservice calls

孤人 提交于 2019-12-10 11:42:34
问题 We are using Specflow for automating our regression suite but now we would like to take it to a next level of automating our webservices. Using the Gherkin “Gven-When-Then”, how can I use / write the webservices calls. For e.g : How do I write my given - when - then for the below request? <ns:request> <ns1:ServiceAuthenticationRequest> <ns1:Password>?</ns1:Password> <ns1:Station>?</ns1:Station> <ns1:UserName>?</ns1:UserName> </ns1:ServiceAuthenticationRequest> … </ns:request> 回答1: Unless you

Handling Exceptions in Python Behave Testing framework

你离开我真会死。 提交于 2019-12-10 03:34:02
问题 I've been thinking about switching from nose to behave for testing (mocha/chai etc have spoiled me). So far so good, but I can't seem to figure out any way of testing for exceptions besides: @then("It throws a KeyError exception") def step_impl(context): try: konfigure.load_env_mapping("baz", context.configs) except KeyError, e: assert (e.message == "No baz configuration found") With nose I can annotate a test with @raises(KeyError) I can't find anything like this in behave (not in the source