R
Rhino
Does anyone know of an online resource that suggests exactly how to do
unit tests on various kinds of methods? A resource that was focussed
particularly on Java would be especially useful.
I don't suppose it matters if the site is focussed particularly on JUnit,
although that it what I am using.
I am mostly interested in best practices for how to test various kinds of
methods and classes, particularly ones that may be a little unusual.
It's relatively self-evident how to unit-test a getter or setter, for
example, but not quite as self-evident how to test a constructor or a
hashcode method.
And in my case, I'd benefit from the advice of experts even on the types
of tests that seem relatively obvious. The ideas that I learned umpteen
years ago for how to test may have changed somewhat by now....
Basically, I'm looking for a website that would answer this kind of
question:
1. Given a setter method, is it sufficient to just attempt to set it to
one value, then that is within the range of its datatype, then use the
corresponding getter to make sure the value was set correctly or should a
proper test try to invoke the setter with values that are the wrong
datatype or out of range for the variable (e.g. if the setter is for a
short, suppy a value that is long or float to make sure that the right
things happen).
2. Given a getter method, is it sufficient to simply invoke it once and
see that it is the value that should be coming back? If not, how what
more should you do?
3. How do you test a constructor?
4. How do you test a method that has a void return?
I expect to have a bunch of other questions along these lines so, rather
than hopping on to this newsgroup for each of them as they come along,
I'd prefer to start with some principles.
I'm hoping the experts here can point me to something that is well-
regarded by the Java community.
unit tests on various kinds of methods? A resource that was focussed
particularly on Java would be especially useful.
I don't suppose it matters if the site is focussed particularly on JUnit,
although that it what I am using.
I am mostly interested in best practices for how to test various kinds of
methods and classes, particularly ones that may be a little unusual.
It's relatively self-evident how to unit-test a getter or setter, for
example, but not quite as self-evident how to test a constructor or a
hashcode method.
And in my case, I'd benefit from the advice of experts even on the types
of tests that seem relatively obvious. The ideas that I learned umpteen
years ago for how to test may have changed somewhat by now....
Basically, I'm looking for a website that would answer this kind of
question:
1. Given a setter method, is it sufficient to just attempt to set it to
one value, then that is within the range of its datatype, then use the
corresponding getter to make sure the value was set correctly or should a
proper test try to invoke the setter with values that are the wrong
datatype or out of range for the variable (e.g. if the setter is for a
short, suppy a value that is long or float to make sure that the right
things happen).
2. Given a getter method, is it sufficient to simply invoke it once and
see that it is the value that should be coming back? If not, how what
more should you do?
3. How do you test a constructor?
4. How do you test a method that has a void return?
I expect to have a bunch of other questions along these lines so, rather
than hopping on to this newsgroup for each of them as they come along,
I'd prefer to start with some principles.
I'm hoping the experts here can point me to something that is well-
regarded by the Java community.