6

I am currently working on a java project and am attempting to build JUnit test classes with Spring. It has been years since I have touched JUnit and I came across a road block that is stopping my progress and have looked up numerous articles online. I would essentially like to post my question on StackOverflow, but I am not entirely sure what kind of code blocks, snapshots, etc to add on to the question that could be useful. Can anyone suggest what would be the most useful bit of information I should add so that my question will not get down-voted to oblivion?

Just an FYI, I have the JUnit test class, the pom.xml file, and the context.xml file as well as a screenshot i can provide for results when running the test (it is not a stacktrace that occurs).

3
  • 4
    Check how to create a MCVE. Apr 11, 2016 at 17:02
  • Thanks, I will go over this. But for a specific question such as mine, particulary with JUnit and Spring, what would be the most useful bit of information I can provide for my question?
    – ryekayo
    Apr 11, 2016 at 17:04
  • 1
    The most useful bit of information I can provide for my question is a MCVE that highlights the crux of the problem you are having.
    – user1228
    Apr 11, 2016 at 19:04

1 Answer 1

12

The best thing you can do is post a Minimal, Complete, and Verifiable example, also known as a Short, Self Contained, Correct (Compilable), Example. Both links contain a bunch of great pointers on asking a good question.

But basically, you need to narrow down your problem to as few lines as possible while still including enough information so we can copy and paste your code to run it on our machines and get the exact same result as you.

What I often do is start over with a blank project, and only include stuff that directly relates to the problem. If I'm asking about functionOne(), no need to include functionTwo(). On the other hand, potential helpers shouldn't have to do anything to my code in order to run it. That includes import statements, any properties required, etc. Hardcode as much as possible.

This can be a pretty annoying process, but it's also the process you should already be doing on your own in order to isolate the problem. Get in the habit of working in small chunks, and this becomes easier.

You should also include specifically what you expect your code to do, what it does instead, and what the difference between the two is. Try to narrow it down to a specific line that's not working how you expect it to. Debugging and print statements come in handy here.

The name of the game is: make it as easy as possible for people to help you. Include everything needed to reproduce the problem, but don't include anything that isn't directly related to the problem. Any less or more just makes it more difficult for people to help you.

6
  • So for my case, where I am asking questions about JUnit testing, would it be helpful to provide the code of my class and the JUnit test case?
    – ryekayo
    Apr 11, 2016 at 18:16
  • @ryekayo Sure, that's a start. But I would also try to get rid of any code in that class that's not related to your problem. If you're trying to test functionOne, then don't bother including functionTwo(). Apr 11, 2016 at 18:18
  • Got it, thanks for the input on this. :)
    – ryekayo
    Apr 11, 2016 at 18:18
  • 1
    @ryekayo No problem. You should also include specifically what you expect your code to do, what it does instead, and what the difference between the two is. Try to narrow it down to a specific line that's not working how you expect it to. Apr 11, 2016 at 18:20
  • 3
    @ryekayo: don't be too surprised when you are creating your MCVE and you suddenly find the solution :) Minimizing a problem to its smallest representable form makes you focus on details you may have missed before.
    – Jongware
    Apr 11, 2016 at 18:22
  • @RadLexus oh trust me, i wish i could find the solution to this! I have looked up the symptoms of this problem and while I was able to resolve many of the problems, the test cases still error out in the progress bar that Eclipse has
    – ryekayo
    Apr 11, 2016 at 18:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .