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 6378267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:59:00+00:00 2026-05-25T01:59:00+00:00

I m trying to do a unit test to a class which load and

  • 0

I m trying to do a unit test to a class which load and read an xml file.
I m using NetBeans.

Here is my class structure,

Class A
{

private String fileName;

A (String fileName)
 {
  this.fileName = fileName;
  load();
 }
private load()
{
//here i load a xml file by given name
} 
public readXml()
{
// read xml file and return list of records
}
}

Using NetBeans, it generates me some test classes with methods

  @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }
 @After
    public void tearDown() {
    }
 @Before
    public void setUp() {
}

and one method which TestReadXml()

where i have to load the file in order to perform unit testing of method “readXml”, because for that clas “A” i hava method “load()” which is called in the cunstrctor in order to load the file and method readXml is use only for reading and returning records.

Thanks

Edit

want to test method readXml(), give a expect result which is in the input xml file.
the preriquest is to load a xml file.
The point is that i dont know where to do this action, so i get an error

java.lang.NullPointerException
    at com.schober.main.ATest.testReadXml(ATest.java:83)

because here
assertEquals(expResult, result);

the result is null

  • 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-05-25T01:59:01+00:00Added an answer on May 25, 2026 at 1:59 am

    You should test all public methods and constructors of a class file. The tests will verify, that every call with every possible input gives the expected result.

    In your case, you could write some tests to test the constructor. Call it with different parameters like

    • A String that represents a readable and valid xml file
    • null
    • A String that does not represent a file or folder
    • A String that represents a folder
    • A String that represents a file which does not contain xml code
    • A String that represents a file that contains malformed xml code
    • A String that represents a file that contains invalid xml code
    • A String that represents a file that contains valid xml code but uses a different schema
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a test class which organizes its test methods using inner
I am using EasyMock to unit test my Java code. The class I'm trying
I'm trying to unit test a class with a number of private methods. Each
I'm trying to Unit Test a class that has many internal functions. These obviously
I'm trying to unit test my routes using the MvcContrib.TestHelper ShouldMapTo <TController> () extension
I'm trying to unit test a private method that I have attached to my
I am using the latest NHibernate 2.1.0Beta2. I'm trying to unit test with SQLite
I'm trying to unit test a custom WPF control using NUnit. The control is
Am trying to get started using TDD on a class which spits out an
I'm trying to unit test some code which utilises a library which has a

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.