Why you should imitate your dependency?
I had a problem with applications from other people. A lot of time I must to integrate with it. Sometimes it is easy or it looks easy. Sometimes it is very, very hard. I have one solution, which let you implementing your system faster, automatically testing and don't be always depend on other applications. The rest of the advantages is on this post.
About solution
The solution is, such as topic suggest, implement some imitations of these dependencies. A lot of applications, we use like repository or like execute and forget. Sometimes other applications do some complicated calculating, but we don't need good result for our application. We need only be sure that our piece of application works well. We haven't been responsible by other applications. Yes, we like, but that responsible take our time, which we should invest in our application.
In Java we can use Mockito to test our solution. We prepare automated tests, which testing our solution. Yes, this is correct, but how many developers know, how other applications works? I think a lot of time, we stub dependencies like we want it to work. This is problematic, because for good test we need everyone when we use our mocked/stubed class, we need to know how it works. I think this is very hard.
I use that solution too, because it is very popular, but now, I think exist better solution. We can only one create our implementation of our dependency. This implementation should be stupid, should be easy, but it should meet the prepared contract, which we need.
For example, we can imitate storing dependency by in-memory database. We can imitate calculating system by a table with prepared solutions. We can cached a lot of responses from dependency and prepare our responses. We have a lot of ways, which we can go. The problem, which I want to resolve is how don't depend on other people during developing and testing system. I want to show you why it is very helpful.
Because we get more knowledge how it works
The problem with dependencies is that we don't know how it works. A lot of time we have some documentation and we trust them, but we can understand it sometimes bad. During implementing imitation of these systems, we should use that system the same like our imitation and test if the result is the same. We must get knowledge how errors will be returned, what the relations are between objects on that system. We need to understand what the author thinks during implementing that solution.
Because we need 100 percent availability
This is natural that the systems are down. If it is not the driver for nuclear power plant I think this is not very bad. Of course we want to develop our system without a break. We need something which replaces our dependency on this moment. When the dependency is down. I think our imitation is good not only for automatic test. This is very good for local manual testing or development/test environment. Not all have a cash for a lot of environments for dependency. Maintenance the environments is very expensive, so I think this is a good way to save money.
Because we need to automate tests
Yes, we can automate our test with real dependency, but we a lot of things integrate by HTTP. If you know this is very slow, so if you use passionately these dependencies, you lost a lot of time. Your solution should be faster and the availability is simple, so the cost of communication and performed the operation is very low. I read about that if a developer must wait for the result of test more than 15 seconds, then it do something else and lost the focus. I think this is correct, I saw it on me. Of course we can use Mockito for dependency, but such I mentioned a lot of time I don't like Mockito, I think this is a necessary evil. A lot of problems on the tests are from wrong mocked functions, wall up our test by Mockito or use too more that framework. I know that problem is between chair and computer, but that framework lets us doesn't think about our tests, our clean code our architecture. It is a solution for the bad code.
Because we don't like create trash for other people
Do you like when someone testing its solution on your environment? I don't, because a lot of things are not clear, our environment is slower and it imitates a real client, so we don't know who real use our environment. I think we shouldn't use the other environment, because we are the next problem which they must fight. Of course we can create the best automate test to check. It is necessary, but when we manually do something, in my opinion, we don't think about clear that trash. If you have your own implementation, your own stub for that dependency, you are not a problem for other people.
We want easy to run all testing modules during developing
I thought about one of the solution. I can prepare the own environment on the container for the dependency. This sounds good, but I got the little problems. This is very costly to prepare. If you think about database a lot of images you find on the net. The problem is with less popular solutions. You must spend a lot of time during this. The second problem is that you must maintenance new environment. It is cool, when you can run it only one and forget, but a lot of thinks doesn't work like that. That needs clear, more memory and a lot of audience.
Because we can develop faster
This is the same what I mentioned on automate test. We save our time to communicate and performing operations. We save our time when the system is down. We save our time when you are the one of the people, who tide systems after use it. We save time when we run application with one click. I think these arguments are enough.
Summary
I prepare a post about How does that correctly. I think this will be published next to this post, so if you want to read about it that is close. This is my checked solution, which I used and still work.
Comments
Post a Comment