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

  • Home
  • SEARCH
  • 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 8622139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:58:49+00:00 2026-06-12T06:58:49+00:00

I am using Mockito for unit testing. I am wondering if its possible to

  • 0

I am using Mockito for unit testing. I am wondering if its possible to send Parametrized input parameters with as in Junit testing
e.g

@InjectMocks
MockClass mockClass = new MockClass();

@Test
public void mockTestMethod()
    {
    mockClass.testMethod(stringInput); 
// here I want to pass a list of String inputs 
// this is possible in Junit through Parameterized.class.. 
// wondering if its can be done in Mockito
    } 
  • 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-12T06:58:50+00:00Added an answer on June 12, 2026 at 6:58 am

    In JUnit, Parameterized tests use a special runner that ensure that the test is instantiated multiple times, so each test method is called multiple times. Mockito is a tool for writing specific unit tests, so there is no built-in ability to run the same test multiple times with different Mockito expectations.

    If you want your test conditions to change, your best bet is to do one of the following:

    • Parameterize your test using JUnit, with a parameter for the mock inputs you want;
    • Run a loop of different parameters in your test, which unfortunately avoids the “test one thing per method” philosophy
    • Extract a method that actually performs the test, and create a new @Test method for each mock you want.

    Note that there’s no prohibition on using mock objects as @Parameterized test parameters. If you’re looking to parameterize based on mocks, you can do that, possibly creating the mock and setting the expectations in a static method on the test.


    Note about runners: This Parameterized test runner conflicts with Mockito’s MockitoJUnitRunner: Each test class can only have one runner. You’ll want to switch to @Before and @After methods or a Mockito JUnit4 rule for your setup, if you use them both.

    As an example, compressed from a different answer that explains more about Parameterized runners versus JUnit rules and lifting from the JUnit4 Parameterized Test doc page and MockitoRule doc page:

    @RunWith(Parameterized.class)
    public class YourComponentTest {
        @Rule public MockitoRule rule = MockitoJUnit.rule();
        @Mock YourDep mockYourDep;
    
        @Parameters public static Collection<Object[]> data() { /* Return the values */ }
    
        public YourComponentTest(Parameter parameter) { /* Save the parameter to a field */ }
    
        @Test public void test() { /* Use the field value in assertions */ }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an unit testing using JUNIT + Mockito to test a method
I'm using Mockito for my unit testing, and I've run across an issue where
I've been trying to get to mock a method with vararg parameters using Mockito:
I'm writing a JUnit test and also using Mockito, and I want to call
I'm using the Mockito library for Java testing and getting errors in Mockito when
I have a Maven-managed project that uses Mockito mocking in its unit tests. I
I'm using Mockito for JUnit tests. So there is a given class A that
Is it possible to mock a class object using Mockito and/or PowerMockito? Something like:
I'm using Mockito for my unit tests and I encounetered a problem with throwing
Is it just hype about testing Java classes with Groovy rather than using Mockito,

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.