Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8850001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:47:52+00:00 2026-06-14T12:47:52+00:00

For an application that retrieves live stock prices I find my unit test assertions

  • 0

For an application that retrieves live stock prices I find my unit test assertions returning false negatives due to price fluctuations between two calls that populate variables which hold the expected and actual test values.

While this is to be expected, I would love to hear different approaches as to how work around this issue. My initial thoughts was to allow for a margin of fluctuation (~2% difference between retrieved stock prices)

This is the code making the Web request to Yahoo in order to retrieve a stock price.


    public string makeWebRequest(string stockSymbol, string dataRequestID)
    {
        string request = webClient.DownloadString("http://finance.yahoo.com/d/quotes.csv?s=" + stockSymbol + 
                                                  "&f=" + dataRequestID).Replace("\r\n", "").Replace("\"", "");

        if (request.Equals("N/A") || request.Equals("0"))
            return "0.00";

        return request;
    }

    public string getPrice(string stockSymbol)
    {
        return makeWebRequest(stockSymbol, "l1");
    }

This is the unit test which makes a “hard coded” (known to be successful) web request for the stock price and assigning the result to the expected variable. Afterwards, perform another call in order the retrieve the price only this time using the applications object.function then assigning it to the actual variable.

The delta between calls is of 300ms


    [TestMethod]
    public void getPrice()
    {
        string expected = request.DownloadString("http://finance.yahoo.com/d/quotes.csv?s=" + testSymbol + "&f=l1").Replace("\r\n", "").Replace("\"", "");
        string actual = yahoo.getPrice(testSymbol);

        Assert.AreEqual(expected, actual);
    }

Any Suggestions? Or should I just learn to live with it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:47:53+00:00Added an answer on June 14, 2026 at 12:47 pm

    Save what your call to server receives and then write unit test that verifies that you can parse that string.
    You can also write a test that verifies that you try to hit right url for specified symbol. Those would be unit tests. Your is integration test.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written an application that retrieves pricing and part options from a SQL database
I am developing an iPhone application that retrieves the data from remote MySQL server.
I'm writing a GUI application that regularly retrieves data through a web connection. Since
I've developing an ASP.NET application that interfaces with Google Maps and retrieves marker information
I have a simple application that retrieves a dataset from the database and converts
I am creating a java application that retrieves a userId from a database, transforms
I am trying to build an application that retrieves continuous streams of xml data
I am working on an application that retrieves files from different URL's. There is
Currently I have a servlet based application that retrieves data from an archived database
I have an JavaEE 6 / EJB3.1 / Glassfish 3.1.2 application that retrieves .xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.