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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:41:15+00:00 2026-05-26T01:41:15+00:00

I have a project using .Net 4.0, VS 2010 and Spring 1.3. Before and

  • 0

I have a project using .Net 4.0, VS 2010 and Spring 1.3. Before and after each of my Integration tests run, I want to be able setup and clean up some data for the test. I was thinking of using custom attributes to do this.

[TestClass]
public class UnitTest1
{
    [TestMethod]
    [PreTestSqlExecute(SqlScript="SetUpDataForMethod1.sql")]
    public virtual void TestMethod1()
   {
   .

To do this, I have created the custom attribute and the Around Method Interceptor

public class PreTestSqlExecuteAdvice : IMethodInterceptor
{
    public object Invoke(IMethodInvocation invocation)
    {
    .

Basically, the problem now is how to get the Test framework in Microsoft to use Spring to create the “UnitTest1” class rather than creating a concrete class directly. For example, I can use a dummy console app with appropriate configuration to do something like this

    static void Main(string[] args)
    {
        IApplicationContext ctx = ContextRegistry.GetContext();
        var ut = (UnitTest1)ctx["mySqlTest"];
        ut.TestMethod1();

This works fine. But when I run the tests directly using visual studio and clicking “Run All Tests In Solution” for example, it does not call the interceptor and execute the before and after code, just goes directly to the test method.

I have tried using AttributeAutoProxyCreator in the config as shown below

<object type="Spring.Aop.Framework.AutoProxy.AttributeAutoProxyCreator, Spring.Aop">
  <property name="AttributeTypes" value="SpringTests.ClassInstanceAttribute"/>
  <!-- Interceptor names can be either of the type IAdvice, IAdvisor, or IAdvisors -->
  <property name="InterceptorNames" value="aroundAdvisor"/>
</object>

with the appropriate attribute on the class

[TestClass]
[ClassInstance]
public class UnitTest1
{

or inheriting from the AbstractDependencyInjectionSpringContextTests

public class UnitTest1 : AbstractDependencyInjectionSpringContextTests

But none of these seems to work. My method interceptor is not being called. So how do I get the Microsoft test framework in Visual Studio to either use spring context to create the Test Classes. Or alternately, get Spring to intercept the concrete constructions of these test classes and inject the Proxy class instead.

Thanks in advance for the help.

  • 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-26T01:41:16+00:00Added an answer on May 26, 2026 at 1:41 am

    Found my own solution, as detailed here – http://www.chaitanyaonline.net/2011/09/25/improving-integration-tests-in-net-by-using-attributes-to-execute-sql-scripts/

    Basically I inherit my unit tests from “ContextBoundObjects”, this lets me inject my own code and do AOP like stuff. I created my own custom attributes so that I can run the pre and post processing Sql scripts.

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

Sidebar

Related Questions

I have a website project that I want to build using CruiseControl.net. On one
I have .NET project using VS 2010 Pro, Some of the class name in
I am in the start up of a project using ASP.NET MVC and have
I have an ASP.Net project using AJAX that I am putting on a server
I have a test project using MbUnit and TestDriven.Net. If I right-click on an
I have a project in ASP.NET MVC1 using VB.NET controlers and JqGrid. it works
I am using ASP.NET Dynamic Data for a project and I have a table
I have a .net 1.1 project in VS.Net 2003 (using C#) in which I
I have a .net project (MySolution.Common) that uses the app.config. I am using the
In visual studio, I have an asp.net 3.5 project that is using MS Enterprise

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.