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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:09:45+00:00 2026-05-30T09:09:45+00:00

I have a presenter class that will spawn a new presenter and view upon

  • 0

I have a presenter class that will spawn a new presenter and view upon successful execution. Prior to spawning the next presenter/view, some business logic executes that I wish to unit test. My issue is that I cannot avoid an actual GUI window appearing when my unit test executes.

Here is some psuedo-code that demonstrates the issue:

// View1 and Model are interfaces
public Presenter1(View1 view, Model model) {
  // ....
}


public void handleOKClick() {
  // Method triggered by view

  String data = view.getSomeUserInput();
  // ... business logic I wish to test  


  if (shouldLoadNextView) {
    // Business logic concluded the next view should be loaded

    View2 nextView = new View2Impl();
    Presenter2 nextPresenter = new Presenter2(nextView, model);
    nextView.setPresenter(nextPresenter);
    nextView.showView();
  }
}

In my unit test, I can mock the View1 and Model instances that I pass to my Presenter1 constructor. I can then check that my business logic interacts with these as expected. What I can’t currently do is prevent the next view from displaying, as my Presenter1 instance will construct a concrete implementation of View2 and display it.

I feel like I’m left with three choices:

  1. Change the design of my class. Perhaps the Presenter1 constructor should take a View2 instance as an argument, allowing me to mock it for the purposes of testing.

  2. Find a cunning way to kill the view from my unit test code, once it has appeared. I’m not sure how best to do this.

  3. Make a more fundamental change to my project class design so that presenters never spawn new views in this fashion.

  • 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-30T09:09:47+00:00Added an answer on May 30, 2026 at 9:09 am

    Time has passed and I’ve since adopted option 1. It feels clunky to pre-construct views when they may not be needed, but equally my view classes are lightweight and cheap to construct.

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

Sidebar

Related Questions

I have a view controller that gets presented modally and changes some data that
My parent ViewController class contains a UISearchBar. I have a UIButton that will push
I have a template class ArrayTemp that creates an array of pointers to type
In Cocos2d, I have read that [[[[CCDirector sharedDirector] openGLView] window] addSubview:someButton]; will add a
I have a view that displays in a UIPopoverController. Before, it just had properties
I have looked and looked, but I cannot find a method that will allow
I have a Singleton class that manages the connection to an external device. The
I have a handle-based class that I need to create a vector of. An
I am playing with a sample WPF application that is tiered in a Model-View-Presenter
I have a math vector class that is designed as follows: class Vector3D {

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.