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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:42:39+00:00 2026-06-15T01:42:39+00:00

I want to create test data at runtime for my junit test cases. As

  • 0

I want to create test data at runtime for my junit test cases. As part of that activity i have choose to write a set of data fixtures and an implementation around it which would create/remove/update test data. These would be called from every Junit class @before and @After methods – @before to setup the test data and @after to teardown the test data.

I have written all this implementation inside the “test” package and have marked the main classes as @component and @autowired these new classes. However when i run my junit test it is unable to create the instances of these new classes and hence the autowire does not seem to work.

I am not sure what more i have to do prior to autowire other than adding following configuration inside the test-config.xml

<context:component-scan base-package="test">
</context:component-scan>

I am using Spring 3.x and Junit 4.

———More information————–

//Business implementation:

//File location: src/main/java/com/abc/prq

package com.abc.pqr

@Service("myservice")
public class MyService{

}

//Junit Test for Myservice class:

//File Location: src/test/java/com/abc/pqr

 package com.abc.pqr;
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations={"classpath:/META-INF/spring/test-Config.xml"})
 public class MyServiceTest {
     @Autowired  
     private ABC abc;
 }

//Data Fixture to create/remove/update test data

//File Location: src/test/java/com/abc/pqr/datafixtures

 package com.abc.pqr.datafixtures
 @Component("abc") 
 public class ABC{
     public void create(){
     } 
     public void remove(){
     } 
     public void update(){
     }
 }
  • 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-15T01:42:41+00:00Added an answer on June 15, 2026 at 1:42 am

    I think that the problem is caused by the fact that you’re not scanning the right package in the spring test context.
    The test-Config.xml file should look something like this:

    <context:annotation-config />
    <context:component-scan base-package="com.abc.pqr.datafixtures" /> 
    

    Hope this helps.

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

Sidebar

Related Questions

I have some kind of test data and want to create a unit test
I want to create NUnit test to ensure that my function does not throw
I have a method CreateAccount(...) that I want to unit test. Basically it creates
i want create a custom json data from the mssql 2008 results so that
This is a function that I want to write a unit test for: public
I have a type and want to create an instance of it with test
I want to create a simple CRUD application to test out the data handling
I have a myism table 'test' which holds some out-dated data, now I want
I want to create test data for an application, and there are a lot
I have a spring application and I want to create a unitary test on

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.