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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:11:48+00:00 2026-06-13T12:11:48+00:00

I wrote a desktop application which basically is a front end for database. It

  • 0

I wrote a desktop application which basically is a front end for database. It is used for create, read, update operations of different linked objects and performs some simple calculation and data aggregation. The MVVM pattern was followed in order to simplify testing.
This morning I tried writing the first test and realized it was not simple as expected.
Unit tests are great for checking the result of a single operation, but unfortunately I have to deal with complex objects which are linked together.
I will try to explain my problems better.
1) I can create and test an object of class A. If I repeat the test 100 times my database becomes polluted. I need automatic procedures to clean it.
2) Objects of class B needs an object of class A for some operations. I don’t think it is a good idea to write a test where both objects A and B are created. what I supposed to be the right way is to use the object created at point 1 as a prerequisites for this test.

I switched to visual studio 2012 express because it has basic support for unit tests but I need some guidelines on how to better use it for my special needs.

Thanks
Filippo

  • 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-13T12:11:49+00:00Added an answer on June 13, 2026 at 12:11 pm

    Writing unit tests for ‘legacy’ code (code without unit tests) can be really hard.

    The problem is that unit testing is all about testing single classes in complete isolation without any dependencies on other code.

    For example:

    public class MyMVVMClass
    {
        public void CreateComplexObject()
        {
            var myDatabaseObject = new MyDatabaseObject();
            myDatabaseObject.DoSomethingComplexWithTheDatabase();
        }
    }
    

    This small code example is impossible to unit tests because it depends on a real database being accessible. These kind of tests are called integration tests. They are important and definitely have their uses but they are not unit tests.

    One of the big patterns that you can use to improve code for testability is Inversion Of Control. This means that you inject dependencies into a class by using some container object that manages the lifetime of these dependencies.

    In your Unit Test you can use tools like Moq to fake those dependencies and make them easily testable.

    I wrote an article about this some time ago which goes into more depth. Maybe it can help: Unit Testing, hell or heaven?

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

Sidebar

Related Questions

I am developing a Java Desktop Application which uses MySQL database. The DB has
Scenario: I have a WPF desktop application which will be distributed on different machines
I am writing for my desktop some application for handling some services. I wrote
I have a Java desktop application I wrote, and I would like a recommendation
As part of my Final Year Project I've developed a desktop application, which fits
I have written a C# desktop (winforms) application which is essentially a clone of
I'm creating a Desktop Java application which needs to store (what could become) reasonably
I was going to migrate a desktop application which is done in java in
I am trying to run a desktop application which is developed in java rmi.
I need to have as part of a desktop application a file server which

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.