This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JUnit testing

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can someone help me with JUnit test, I've read the documentation about it but still don't get  how to test it? Thank you.
 
Marshal
Posts: 79978
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before you test that code, stop using Calendar or the buillt‑in Date class. Use the newer classes as described in the Java™ Tutorials.
 
Sheriff
Posts: 28331
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Before you test that code, stop using Calendar or the buillt‑in Date class. Use the newer classes as described in the Java™ Tutorials.



It looks like the whole point of the code is to write a class which represents time-stamps. Yes, I know that's a WTF and it's the exact opposite of best practice. But apparently there are still some teachers who think it's a good way to practice coding.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Asking how to do JUnit testing is a little like asking how to program: it's a complex issue.  Can you give us some more context?  Have you been told to "add testing" to your program by a teacher or employer?  Is this for your own research?  Are you using an IDE?  Which one?  Are you using Maven?  Gradle?  Is this for a company that runs CI (continuous integration)?  In other words, is this part of a larger software development system or just for you?

After we determine your development environment, you would start writing unit tests.  This is a new program that will run your tests for the original program.  (You actually test methods).  I would start with very simple tests and build from there.

A JUnit tutorial would be a good place to start.  I would start by googling junit 5 tutorial for beginners.  Sorry, I can't recommend any specific one; I'm not familiar with them.  
 
Campbell Ritchie
Marshal
Posts: 79978
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I resisted the temptation to say that writing your own date/time classes is a waste of time, but at least it would have ben easier with a well‑designed class underlying that.

Of course, you should be able to extract the information without using an intermediate class at all, so I tried something on JShell:
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic