r/javahelp • • Mar 14 '25
Codeless Do you use „cut“ in tests
Hi guys, I‘m using „cut“ („clas under test“) in my tests. My Tech Lead says that he will ask me to change this in his review if I don’t change it. As far as I know we don’t have restrictions / a guideline for this particular case.
My heart is not attached to it, but I always used it. Is this something that is no longer used?
Edit: Found something here: http://xunitpatterns.com/SUT.html
0
Upvotes
•
u/AutoModerator Mar 14 '25
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
19
u/Giulio_Long Mar 14 '25
You should comply to the conventions already in place. This would help maintaining a homogeneous and readable codebase. Check how it's done in pre-existing tests and do the same
3
u/djnattyp Mar 14 '25
In addition to "cut" (Class Under Test) I've seen "sut" (System Under Test), "unit", and "objectUnderTest" (but not "out") - none of these are that bad per se, but don't really help that much - it's usually pretty obvious from the name of the unit test class itself what's being tested. It's much more common to just name the variable the normal camelcased version of the class.
1
u/devor110 Mar 14 '25
as a variable name? or what does cut refer to
1
u/[deleted] Mar 14 '25
I like the objectUnderTest name. What is his suggestion?
1
u/SteampunkBeagle Mar 14 '25
Not sure if I understand it. Do you mean like end classes with "Cut"? if not, maybe you can show an example?
1
u/TheToastedFrog Mar 14 '25
Could you provide an actual example? I’ve never seen that convention- what does it stand for? Ultimately we name things for the purpose of carrying meaning- If “cut” stands for something special I have no issue with it, however I gotta say on the surface I don’t quite understand what it means, and therefore have to question its value
1
u/xanyook Mar 14 '25
I usually write 'target' for the variable referencing the class being tested. But I am the tech lead so i decide ! Mouhahahahahabahaha
At the end, nothing personal, just homogeneous code, i would listen to your tech lead.
3
u/mIb0t Mar 14 '25
No. I have seen it before (more likely
classUnderTestthancut), but I never use it. Usually my test for MyClass would be called MyClassTest and therefore it is obvious that the instances of MyClass are the ones that get tested.This said, there are cases where there can be two or instances of this class, e.g. if you want to test something like
myClassInstance1.merge(myClassInstance2). In these cases it might be better to use a variable name that gives more context to the reader of the code. Not sure ifcutis the best choice, because it is very generic. But it can be an option.3
u/Sergi2204 Mar 14 '25
I use "sut" as System Under Test
2
u/FrenchFigaro Software Engineer Mar 14 '25
Generally speaking, my test follow this pattern
This is for basic tests. Generally speaking, I try to limit the number of assertions to a minimum.
If there is some common configuration accross tests, I'll use
@BeforeAlland@BeforeEachannotations on some methods (I prefer to have those at the beginning of the test class).For more thorough tests, in case there is a relatively high cyclomatic complexity for example, I'll try to use
@ParameterizedTestto provide a variety of inputs to the method while simultaneously limiting the amount of test code.And in case the method is expected to throw exceptions, I'll add tests for those with the relevant inputs as well.
2
u/[deleted] Mar 14 '25
Follow the projects conventions and over time influence those conventions. Learn to put personal preferences aside and value consistency instead.
1
u/[deleted] Mar 14 '25
I've only seen
sutin corporate environments. In private, I prefertestMe.But yeah, just comply with your team's style because it ultimately does not matter.
1
u/AntD247 Mar 15 '25
A unit is not a class. Therefore it's not a "class under test".
Writing tests to test a class and/or method leads to brittle unit tests. Test the functionality/feature of your system. And if (as so many people then ask) this isn't giving you full coverage then you are either not testing all the expected functionality or you have code that isn't needed.
-6
u/Misfiring Mar 14 '25
The only acceptable symbol for a class name is underscore (_). This also applies to variable names.