Isolation dependencies without control inversion

I am working on a corporate application, which largely depends on message queues, com +, databases, httpcontext, static utility classes, etc.

Since in our system 600 projects it is not practical to rewrite in order to use the inversion of control. Typemock claims that they are the only isolation environment that does not require you to rewrite your code to use IOC .

Does anyone know how TypeMock implemented this level of functionality and are there any alternatives? Even if I had to rewrite my application to use control inversion, I would have to write wrapper classes for message queues, httpcontext, etc. It just sounds funny to me, right or wrong, to think that Typemock is the only viable option for my scenario.

thanks

+3
source share
4 answers

You are right to think that TypeMock (or another similar tool for bullying) is the only viable option.

, , , , , .

Java JMockit - .

JMockit , API java.lang.instrument. , / . , -, /, . . , (.. , , -, , JVM).

+1
+1

:

public class MotherClass
{
    private SubClass _subClass;

    public MotherClass()
    {
        _subClass = new SubClass();
    }
}

public class SubClass
{
    public string SomeMethod()
    {
        return "Hello";
    }
}

IoC. Typemock Isolator :

    [TestMethod]
    public void TestMethod()
    {
        var fake = Isolate.Fake.Instance<SubClass>();
        Isolate.Swap.NextInstance<SubClass>().With(fake);
    }

SomeMethod :

        var fake = Isolate.Fake.Instance<SubClass>();
        Isolate.WhenCalled(() => fake.SomeMethod()).WillReturn("Bye");
+1

IOC. , . , , , ( , ), . - . , .

. . , . , ( EasyMock, , - JMock, Mockito). -, -. , ( , ).

(Aspect Oriented, , Typemock) , . , ( ), - .

, , Groovy. Groovy Java ( -) . Google Groovy .

0

Source: https://habr.com/ru/post/1712614/


All Articles