DEV Community

Amir Mullagaliev
Amir Mullagaliev

Posted on

Testing

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 my pom.xml file:

Image description

  • Secondly, I created the test directory inside of the src directory:

Image description

  • Separated in java for unit testing and integration for integration testing, and added resources directory to create samples of my .toml config file and .json response to run the tests:

Image description

  • Implemented the unit tests for every important module:

Image description

Mock Server

For testing my api I had to use framework WireMock. Here's my test function using both WireMock and JUnit5:

Image description

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

  1. To easily maintain and test your project, you must write small blocks of code, break everything down into small pieces(methods).
  2. Testing is really important part of SDLC, every tool/application/web-service would be so vulnerable without it.
  3. No enough tests exist.
  4. 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.

Top comments (0)