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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:49:47+00:00 2026-06-04T03:49:47+00:00

Here are some (overly) simplified code example to describe my unit testing method. CompanyDataSet.xml

  • 0

Here are some (overly) simplified code example to describe my unit testing method.

CompanyDataSet.xml

<dataset>
    <company company_key="100" company_name="OldName" />
</dataset>

CompanyDaoTest.java

@Test
public void testUpdateCompany() {
  CompanyDao companyDao = new CompanyDao();
  IDatabaseConnection dbConn = createConnection();

  IDataSet dataSet = createDataSet("CompanyDataSet.xml");
  DatabaseOperation.CLEAN_INSERT.execute(dbConn, dataSet);

  companyDao.updateCompany(100, "NewName");

  // What is a good way to assert updated company data ?
}

I came up with two ways to assert company data.

Create another dataset xml as expected dataset.

another XML

<dataset>
    <company company_key="100" company_name="NewName" />
</dataset>

Assert part in Java

IDataSet actual = dbConn.createDataSet(new String[]{"company"});
IDataSet expected = createDataSet("CompanyDataSet_expected.xml");

Assertion.assertEquals(expected, actual);

Just load the company object through DAO, and compare the properties.

you should get the idea.


My Problem

The first way is pretty easy to write, but I have to create another XML file for each different update method. It dose not sounds like a good idea to create so many data set XML files.

The second way is straightforward, however, when there are different update methods, the test class will filled with methods that assert different properties with different value. And Lots tests will broke if there are something wrong with load method.

Is there a good way to assert the data ? is it possible to avoid the problem I just described (or it dosen’t really matter) ?

UPDATE

Since there is no one answer the question, I decide to accept my answer.

  • 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-04T03:49:49+00:00Added an answer on June 4, 2026 at 3:49 am

    Here is another way to assert the data.

    Since I already have the actual IDataSet which contains current data of database. I can simply retrieve the data from it.

    I use the example in question, this is what I do

    @Test
    public void testUpdateCompany() {
      CompanyDao companyDao = new CompanyDao();
      IDatabaseConnection dbConn = createConnection();
    
      IDataSet dataSet = createDataSet("CompanyDataSet.xml");
      DatabaseOperation.CLEAN_INSERT.execute(dbConn, dataSet);
    
      companyDao.updateCompany(100, "NewName");
    
      IDataSet actual = dbConn.createDataSet(new String[]{"company"});
      ITable companyTable = actual.getTable("company");
    
      assertEquals("NewName", companyTable.getValue(0, "company_name"));
    }
    

    It’s somewhat verbose if there are many properties to check, but it should be pretty easy to handle


    UPDATE

    Although this way dose solve the problem, test will not couples on unrelated method anymore. But, when it comes to maintenance, it actually has the same overhead first two way have, even worse. Because I have to wrote column name(lots of them) inside the java code, and there is no way to validate this.

    Our team decide to use dataset to assert data whenever possible. The main reason is we want to keep our test data as small as possible, and easy to assert.

    So the answer of the question will be use the dataset

    However, there will be some downsides too, here is how we deal with it for now:

    1. Organize the XML files :

      Location : The dataset XML files will be in the same package of the test classes.

      Naming : the XML file will start with the test class name, and add method/state name if necessary. for example : “companyDao-updateCompany-expected.xml”

    2. Make XML sync with database.

      We will use Untils to generate DTD file from database on the fly, and use it to validate the XML. We rarely change column name, so the overhead should be low.

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

Sidebar

Related Questions

Here's some example code: class Obj attr :c, true def == that p '=='
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here's some code (full program follows later in the question): template <typename T> T
Here is some code: class Person def initialize(age) @age = age end def age
Here's some code: DirectorySearcher searcher = new DirectorySearcher(); searcher.Filter = (&(objectClass=user)(sAMAccountName= + lstUsers.SelectedItem.Text +
here is some code I've been working on, basically I need to set up
Here is some example data: data = data.frame(series = c(1a, 1b, 1e), reading =
Here is some C++ code I'm playing around with: #include <iostream> #include <vector> #define
Here is some code on the javascript side for form-based uploads: iframe.setAttribute('src', 'javascript:false;'); I'm
Here's some of the code, the box displays fine but none of the options

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.