question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proper testing pipeline

See original GitHub issue

Hello,

I’m in the process of evaluating Javalin in Java to replace a Spring service that is in the making. So far I’m excited about the simplicity but power and control it has.

I am wondering on how to properly unit test the controllers. In Spring, there is the possibility to “mockMvc”.

In Javalin, I am testing the controllers’ handle(ctx). Unfortunately, this does not work very well, because some classes are not mockable, e.g. the result from ctx.validatedBodyAsClass(...).

Alternatively, I could also mock HttpServletRequest with mockito. But this would result in mocking-hell, because I would have to mock every sub-object, like the writers, etc…

Or create a complete HttpServletRequest-implementation for testing.

How are you unit-testing your controllers? Do you have guidelines and examples in Java?

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tipsycommented, Sep 27, 2018

If you can write your tests in Kotlin that would be a great solution. I don’t remember if I added any mock tests to the repo. I should probably write a tutorial.

0reactions
tipsycommented, Sep 28, 2018

Does the context object need all the functions?

IMO, yes. You could argue that a lot functions could be moved into Request and Response classes on the Context, but that would instantly add a lot of noise to controllers (ex: calling ctx.request().pathParams(":user-id")). You could also make an interface which takes a Context, a Request, and a Response, but that would similarly create a lot of noisy method signatures and lambdas.

I went through the different alternatives when designing the API, and this was found to be the best solution.

I’m worried that by introducing single implementation interfaces, the code will be harder to read and understand for new users and new contributors (this also worries me about nesting functionality into different objects on the Context).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Pipeline 101 For Frontend Testing - Smashing Magazine
Automated testing can give you much confidence in merging your changes, especially in extensive refactoring or working with your teammates.
Read more >
The CI/CD Pipeline: Why Testing Is Required at Every Stage
Testing throughout the pipeline allows you not only to properly test your code, but can also help you speed up your deployment process....
Read more >
CI/CD Pipeline: A Gentle Introduction - Semaphore
A CI/CD pipeline helps you automate steps in your software delivery process. Understand the basics, best practices and how to get started.
Read more >
The 7 essential stages of a CI/CD pipeline - Tutorial Works
Acceptance tests are a way of ensuring that your software does what it is meant to do, and that it meets the original...
Read more >
Oil Pipeline Testing Methods
This technique is appropriate for longitudinal crack inspection though there has been mixed success in its application as the algorithms utilized to analyze...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found