Testing
Amir Mullagaliev
Posted on November 12, 2024
Introduction
This week we are continuing working on our Release 0.1
open-source project. For the first time in my college journey I was tasked with implementation of my own tests for the tool we'd earlier created during this term. Will tell you straight, it wasn't easy, I really hate testing; for the reason, that it's time consuming and sometimes I had to hit my head off the wall. To come up with the solution.
Tools I Used
To write my unit tests I used framework called JUnit5. JUnit5
is programmer-friendly testing framework for Java
and the JVM
.
To test my API I had to create a mock server, WireMock framework helped me with it which is integrated with JUnit5
. WireMock
is a tool for mocking HTTP services.
How to Set Up The Tools
- As my project based on
Maven
framework, first thing first I had to add the dependencies to mypom.xml
file:
- Secondly, I created the
test
directory inside of thesrc
directory:
- Separated in
java
forunit
testing andintegration
forintegration
testing, and addedresources
directory to create samples of my .toml config file and .json response to run the tests:
- Implemented the unit tests for every important module:
Mock Server
For testing my api I had to use framework WireMock
. Here's my test function using both WireMock
and JUnit5
:
Challenges
It was the hardest lab that took me a huge amount of time to end up with a final solution. It was really complex process because first interaction with testing always hard. Here are the challenges I faced:
- Huge Blocks of Code
Due to that my project structure isn't brilliant I had hard times testing. The thing is that I used huge blocks of code for execution of the certain tasks, and only separated helper methods. Good lesson... Since now I know, everything should be broken down into smaller pieces, in order to make maintenance and testing easier.
Huge blocks of code caused the problems with passing the tests.
- Mock Server
To test my api and imitate server I had to call my groupmate Theo. He helped me set up and figure out how mock servers work. He showed me a new tool that I'd never used before WireShark
. WireShark
is a packet sniffer and analysis tool. It captures network traffic from ethernet, Bluetooth, wireless (IEEE. 802.11), token ring, and frame relay connections, among others, and stores that data for offline analysis. Theo helped me a lot, we had a call that lasted for almost 6 hours.
Things I Learned
- To easily maintain and test your project, you must write small blocks of code, break everything down into small pieces(methods).
- Testing is really important part of SDLC, every tool/application/web-service would be so vulnerable without it.
- No enough tests exist.
- Ask help from people around.
Conclusion
I still don't like testing. However, as I mentioned earlier it is important part of SDLC. I'm happy that I was able to make it, of course not without outer help.
Posted on November 12, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.