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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:19:52+00:00 2026-05-20T00:19:52+00:00

I am new to specflow and a have a doubt about how to mock

  • 0

I am new to specflow and a have a doubt about how to mock my
controller dependencies.
For instance I have a UserController class which depends on my
UserRepository class that a pass to the controller class on its
constructor.
So using Moq I am doing something like this:

var mock = new Mock<UserRepository>();
mock.Setup(m => m.ListAll()).Returns(new List<User>());
var browser = new IE(string.Format("http://localhost:4265/{0}",
username));

But my controller is not using the mocked object, how should I do
that?

Thanks

  • 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-20T00:19:52+00:00Added an answer on May 20, 2026 at 12:19 am

    You are mixing three (atleast) test framework, which ofcourse is cool, but you should probably stop and consider what it is you want to test.

    Watin is good for testing your UI as it controls a browser instance. I find it good at making regression tests http://en.wikipedia.org/wiki/Regression_testing

    Specflow is great as well – personally i like to use it for closing the gap between business developers and (us) software developers as we can actually define requirements in terms we both understand (and probably other parts of the organization as well) I don’t want to start a flame war, but it can introduce more problems than it solves, unless you focus on its real values. We use this at work by testing the service layer (one layer below the controllers in the presentation layer) and we actually only mock the database, external services and file system etc – which makes our specflow tests some kind of integration tests.

    Moq is a mocking framework and can ofcourse be used in any kind of tests (like i just let it slip we do) but this is such a great tool for unit testing.

    So to return to your question. If you want to make one test to find all your bugs, you’re in trouble 😉 I know you don’t want that – that was just a silly suggestion i made – but really, if you just want to do integration tests (tests running from the UI down through several layers/dependencies) you could easily mix different testing frameworks like you are now, but then why mock the user repository? Is that because you don’t want to hit the database?

    Anyways one way to do the integration test you seem like you want would be to configure your solution to use a mock – or perhaps a stub would do (create a fake userrepository that returns the data you want to test with) – you should use a Dependency framework like Unity, Ninject or structure map (boy let’s not start a war about what framework to use) and have the test url Watin is using launch your site using a configuration with the fake/mock repositories.

    You could on the other hand do unit testing on your controllers, services etc. You might even want to try out TDD but that’s a whole other chapter i can’t cover here!

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

Sidebar

Related Questions

New to PHP and MySQL, have heard amazing things about this website from Leo
I'm new to SpecFlow, and am setting up a number of test features/scenarios that
New Android programmer here. I have a Service which performs socket management and async
New to DDD here and have a architecture question which should be a typical
New to XML. I have a 3rd party webservice that supplies an XML document
New to cpp (Java guy). I have 3rd party library that has method sendMail(txt).
I've got a handful of specflow tests that look something like this: Scenario: Person
NEW EDIT: I have narrowed my problem to this - i have a view
new to java and brand new to the site. I have a JLabel added
I'd like to extend the Test Harness I have written in SpecFlow to be

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.