Results 1 to 8 of 8
  1. #1
    nvkuriseti is offline Member
    Join Date
    Jan 2015
    Posts
    7
    Rep Power
    0

    Default Junit Test case for reading field from a file

    I have JUnit exposure only in writing simple programs.
    Here I have one of the usecases requirement pupose I am generating data file(s) by Java programming and calling this data by Hashmap. My file containing two columns (1) TimeStamp (2) Speed. The file is tab formatted file. The business requirement is to check wether the first column should not be 00000000000000 or NULL or BLANK. My question is, how do I check the first field in a file contaning valid information in Junit test case? Please suggest me how to write.

    Sample File: (\t - tab delimited)
    1421103602000\t542
    0000000000000\t989
    <NULL> \t000
    1421103603000\t588
    1421103604000\t700

    Unfortunately, I am unable to send my Java code here, It was giving some error while attaching in this thread.

    Thanks,
    Venkat

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    13

    Default Re: Junit Test case for reading field from a file

    I would expect you to have code which reads the file and you would check if that code is functioning properly by checking the data it has read in. You're not going to unit test data in a file.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    nvkuriseti is offline Member
    Join Date
    Jan 2015
    Posts
    7
    Rep Power
    0

    Default Re: Junit Test case for reading field from a file

    Quote Originally Posted by gimbal2 View Post
    I would expect you to have code which reads the file and you would check if that code is functioning properly by checking the data it has read in. You're not going to unit test data in a file.
    Hello gimbal2, thanks for your reply. Have to unit test the data in a file. Have written the UnitTest case to call the file but want to check to read the file data and check wether the data contains NULL/BLANK values in both fields. Want to validate first field contains NULL data as one unit test case and second field contains NULL data as another test case.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    13

    Default Re: Junit Test case for reading field from a file

    Repeating the same thing over again does not make things clearer. Let me try it in another way: what is stopping you from doing that?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Junit Test case for reading field from a file

    There are two possibilities here. The first possibility is that you have a number of files which contain invalid data and some which contain valid data. You want to use those to Junit test your methods for validating files. That is reasonable. The other possibility is that you want to use a Junit test to check the validity of a data file during normal use of the application. That is not the purpose of Junit testing. Junit tests are not run during normal use of an application. They are a development tool.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Junit Test case for reading field from a file

    I get the impression the JUnit test is to validate a file generated by the code under test.
    So the test executes the method and then loads the generated file and checks it's OK.

    Which brings us to gimbal's response...what is preventing the OP from reading in the file and checking the values?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Junit Test case for reading field from a file

    Quote Originally Posted by Tolls View Post
    what is preventing the OP from reading in the file and checking the values?
    Clearly, nothing. Perhaps I misunderstood (or read more into) what the OP wanted to achieve.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Junit Test case for reading field from a file

    Quote Originally Posted by jim829 View Post
    Clearly, nothing. Perhaps I misunderstood (or read more into) what the OP wanted to achieve.

    Regards,
    Jim
    No guarantee either of us understood the problem properly, to be fair.
    :)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. junit test case error
    By acmohan in forum New To Java
    Replies: 7
    Last Post: 07-12-2011, 01:13 PM
  2. How to track Save And open a Junit test Java file?
    By jaydip.biswas in forum Eclipse
    Replies: 0
    Last Post: 03-15-2010, 06:44 AM
  3. Problem in reading HTML input field while uploading file
    By sudipanand in forum Java Servlet
    Replies: 1
    Last Post: 11-27-2008, 09:26 AM
  4. Junit test
    By alice in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 01:24 AM
  5. Reading a Field in a Binary File
    By janakiram.attuluri in forum Advanced Java
    Replies: 2
    Last Post: 01-09-2008, 10:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •