Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Genne23v
Genne23v

Posted on

     

Adding Unit Testing to OpenSSG

I had felt the need to package myOpenSSG likenode.js modules. I should have done packaging at the beginning of the project due to lack of my Java knowledge. I had delayed to find a way to package my app, but I tried to useGradle. There are other ways to package Java command line app. I decidedGradle because one of repos that I found usesGradle.

❯ gradletest                                                                                     ─╯BUILD SUCCESSFULin723ms4 actionable tasks: 3 executed, 1 up-to-date
Enter fullscreen modeExit fullscreen mode

I can run the test quickly with Gradle now

I choseJUnit for my unit testing since it's the most popular Java testing framework. So I believe that learningJUnit will be great asset for me. And I had a bit of exposure from writing unit tests forCrowdin CLI project before. I know writing good test requires a lot of thinking and skills, however,JUnit assertion methods are less and simpler than Javascript assertions.

I think writing unit tests is another important step to review my code to improve the logic and split the functions whenever necessary for better readability and easier modification. Since I did some refactoring work to split my code into much smaller chunks, writing unit test is not much difficult. But I found some errors while writing tests. One of the errors was ingetUrl().getUrl() is a recursive function that each child node calls parent node to complete file path. I realized that the root node is not add its data. So the link in sidebar menu has never been correct. And it didn't even add file extension after returning file path. And I updatedDomNode copy constructor as perSpotBugs suggestion to deep copy the object. I had a doubt that it shouldn't be a deep copy in this case, and my unit test proves that I shouldn't have done that. And I also found thatsetParent() did not add the child to its parent. So the child knows the parent, the parent didn't.

There are many bugs and edge cases while writing my tests, but I leave them for now as I need a major update to my argument validation logic as its complexity is too high right now. Moreover, it's almost impossible to read the logic, even myself. And I have some errors that are not handled properly. What's good about unit test, when I make a change, it can find things that break from my change. So I can prevent another bugs from my change. I had some test writing experiences in a co-op and open source projects. I couldn't understand why we write simple tests all over. Test didn't seem to do important work. But now I know the meaning of meme that the guy was disappointed by the co-worker who procrastinates writing unit tests. Especially, it's more important when the code base is large that hundreds of developers are working on. Unit test makes developers find the breaks early enough. And release process much faster with robust testing.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Location
    Toronto, ON
  • Education
    Seneca College
  • Joined

More fromGenne23v

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp