• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Wondering if this setup is JUnit compatible, or requires a different solution?

 
Ranch Hand
Posts: 76
IntelliJ IDE Spring BSD
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I currently have an intresting situation occuring with my code, and after hacking away at what turned out to be a dead end for the last two weeks, I'm here asking those smarter then I to educate me on where I went wrong, and how I can perform my intended task correctly.

The setup:

We have a set of classes that perform various tasks but do so on one object that they pass around. Actions are performed to this object in each class before finally being pocessed and then sent back to the display layer for front end processing. This is a brief description of how the process works.

A collection of users is submitted via front end form
The collection of users is processed into an object with various parameteres set within.
Multiple classes with various methods that process the object that was just created are executed one at a time. In each class, the object has various methods that perform tasks on certain actions, such as formulas, validation, etc...
the object is then sent to the front end for display of the processeed object.

The task:

I'm attempting to build JUnit tests to help automate testing for this group of classes. This is how i have it configured

testConfiguration - instead of a form submission, I create a collection of users in various configurations based upon what we need to do for testing

testMain - This is the "root" class. It takes a configuration from the testConfiguration class needed for the current test run, creates it into an object with various parameters based upon the users passed, and then passed into the various classes for furthur processing

testClassesProcess - various classes that take the processed object from testMain, perform variouos actions on it (mainly mathmatical type methods) and then retun.

The issues:

Ran into a few really. The first is that you can't pass parameteres to functions in JUnit tests, as it'll come up with initializeErrors. Also the @Autowired annootation in the classes being tested error out with nullpointerexception, turns out that if enter the classes being tested from the JUnit suite, they can't seem to resolve the variable that would be used with no issue when executed via the application normally.

WE currently use java 1.7 with hibernate, spring, and junit to help give a visual of our stack.

So I'm wondering if after describing my situation if I'm trying to make junit put a round peg in square hole, if I'm just using junit wrong, or if there's a better solution that I could use to test this setup.

EDIT: My apologies if this seems vague. It's a workplace issue so I try not to give away anything propriatory, and to make it so others could relate.
 
Marshal
Posts: 16631
278
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since your description of the problem is vague, you're going to get a vague suggestion to fix it.

I would work on isolating the tests more and doing more localized setup. Also, what you've written may not actually be unit tests. See the criteria that Michael Feathers sets for unit tests.
 
Chris Creed
Ranch Hand
Posts: 76
IntelliJ IDE Spring BSD
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Since your description of the problem is vague, you're going to get a vague suggestion to fix it.

I would work on isolating the tests more and doing more localized setup. Also, what you've written may not actually be unit tests. See the criteria that Michael Feathers sets for unit tests.



Well that's the problem with working and needing advice. If you provide detailed answers, you wont' need them because you'll be fired within the week for letting out propitiatory secrets or whatever, hence vagueness.

Ya from a brief overview of the google search you provided it's looking not to be as there's multiple classes that are required in order to fully test properly. Of course that brings up the next question of what kind of testing do I need, or can I test this at all?
 
Junilu Lacar
Marshal
Posts: 16631
278
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again, it's hard to give advice on how to test "this" when it's not very clear what "this" really is. I would follow this week's guest author Chris Birchall's advice here: https://coderanch.com/t/643469/patterns/engineer-Legacy-systems-APP-servers#2957487 to try to carve up your app into more independent components. Refactor your code so you're using Dependency Injection more. DI usually leads to loosely coupled components that are easier to unit test.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic