😎 일상/💻 개발 관련 주저리

Writing testing code: Benefits and Limitations

락꿈사 2024. 3. 3. 16:02

 

This week, I wrote down the testing code at work, and It was the very first time to wrote testing code in Pytest and Django environments. Actually, I had experience writing testing code with Java and Spring frameworks, But it was because of the study of how to write testing code, rather than I truly needed it. This time I felt a strong need to write it down and I'm going to share that experience briefly in this article.

 


1. The benefits of writing testing code

First of all, The biggest benefit would be the assurance that the target method or function's action. If you are making a project in which the complexity is not that high, yes, you wouldn't feel this benefit that big. But the bigger your project gets, the higher the complexity of your project and you may feel that you're not assure your code is working well anymore.

 

 

From my side, the target action that I wanted to test was this.

 

It was troublesome switching Database and code to check related Objects2 was created whenever the code was updated. Furthermore, there were more than 10 target objects to test which made the complexity higher. 
After I wrote down the testing code, It was succeded in simply executing the Pytest commander.

 

 

2. Challenges that I encountered

In the Progress writing the testing codes, necessary but the hard challenges were there. Let me show the difficult situation that I encountered.

 

Since the dependencies of the target Objects, I had to make other related objects to make the target object. And surely you should investigate the dependencies of target objects If you are not sure about the target. This is the biggest difficulty that I experienced in the whole process of writing testing code. I guess this hard situation is what most of the engineers who trying to write a testing code have encountered. 

 

 

3. The limitation.

Although there is a lot of assurance that testing codes give us, definitely there are some limitations. And It was the possibility that it wouldn't give me the same result and performance "in another environment". 

 

The environment we expect our codes to work is ultimately the production. But most of the testing environments, may not same as production in the aspect of the amount of data and everything. So the only thing we could expect for the testing codes is the action of the target.  

 


 

Considering the above benefits, challenges, and limitations, I think the benefits of writing testing codes are not just the productivity that it gives to us, but also the progress to writing down on it. Investigating the target and studying the dependencies are meaningful itself. As a result, with this experience, I'll actively use it in my work.