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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:55:28+00:00 2026-05-14T15:55:28+00:00

I have a class API which has full code coverage and uses DI to

  • 0

I have a class API which has full code coverage and uses DI to mock out all the logic in the main class function (Job.Run) which does all the work.

I found a bug in production where we werent doing some validation on one of the data input fields.

So, I added a stub function called ValidateFoo()… Wrote a unit test against this function to Expect a JobFailedException, ran the test – it failed obviously because that function was empty. I added the validation logic, and now the test passes.

Great, now we know the validation works. Problem is – how do I write the test to make sure that ValidateFoo() is actually called inside Job.Run()? ValidateFoo() is a private method of the Job class – so it’s not an interface…

Is there anyway to do this with NMock2.0? I know TypeMock supports fakes of non interface types. But changing mock libs right now is not an option. At this point if NMock can’t support it, I will simply just add the ValidateFoo() call to the Run() method and test things manually – which obviously I’d prefer not to do considering my Job.Run() method has 100% coverage right now. Any Advice? Thanks very much it is appreciated.

EDIT: the other option I have in mind is to just create an integration test for my Job.Run functionality (injecting to it true implementations of the composite objects instead of mocks). I will give it a bad input value for that field and then validate that the job failed. This works and covers my test – but it’s not really a unit test but instead an integration test that tests one unit of functionality…. hmm..

EDIT2: IS there any way to do tihs? Anyone have ideas? Maybe TypeMock – or a better design?

  • 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-14T15:55:28+00:00Added an answer on May 14, 2026 at 3:55 pm

    The current version of NMock2 can mock concrete types (I don’t remember exactly which version they added this, but we’re using version 2.1) using the mostly familiar syntax:

    Job job = mockery.NewMock<Job>(MockStyle.Transparent);
    Stub.On(job).Method("ValidateFoo").Will(Return.Value(true));
    

    MockStyle.Transparent specifies that anything you don’t stub or expect should be handled by the underlying implementation – so you can stub and set expectations for methods on an instance you’re testing.

    However, you can only stub and set expectations on public methods (and properties), which must also be virtual or abstract. So to avoid relying on integration testing, you have two options:

    • Make Job.ValidateFoo() public and virtual.
    • Extract the validation logic into a new class and inject an instance into Job.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 426k
  • Answers 426k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ref hidden_field or hidden_field_tag <% form_for(:request, :url => requests_path) do… May 15, 2026 at 12:35 pm
  • Editorial Team
    Editorial Team added an answer JFrame shouldn't be popped as long as you don't want… May 15, 2026 at 12:35 pm
  • Editorial Team
    Editorial Team added an answer FrameworkPropertyMetadata only works for FrameworkElement-derived classes. I reproduced your problem… May 15, 2026 at 12:35 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.