File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

junit - basics

 
petr pavlovich
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello people!
All the best!
Help me understand the writing junit test.
This is my first junit test in life.
Assignment:

Methods return the 6 numbers, which are the coordinates of three vertices of a right triangle in a Cartesian coordinate system

There is a method that returns the right-angled triangle:

Requires: junit test to write code that checks the method getRtriangle that he actually returns a right triangle

My attempt to build a junit test.
//As I understood from the job myself to write the implementation getRtriangle






Do I do it?
Tell me, please.
Are there any errors?

Thank you!

 
Brian Burress
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
petr pavlovich wrote:Hello people!
Do I do it?
Tell me, please.
Are there any errors?


Petr,

I do not understand what your class is trying to do. What is the resault of the test? I suspect it fails as this is the last line of the junit code.

As a broad statement, I don't think the JUnit test is valid but I do not know what "valid' really is.

What does the RtriangleProvider do? It looks like it returns various points. The only thing you can test for RTriangle, per se, is that the points are returned as expected (assertEquals would be one JUnit statement to consider). I suggest RtriangleProvider implement the RTriangle interface and should also have a constructor accepting the points and that you use that constructor instead of a static getRTriangle method.

From there I am not really sure what to say. If you are trying to confirm whether or not the triangle is a right triangle, then to me it would made sense to have an "isRightTriangle" method returning a boolean or something like that coded on the interface that your class implements. Your test(s) would then be able to feed sets of data points in and the test would assert that isRightTriangle is true or false as appropriate based on the points provided.
 
petr pavlovich
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


test method for testing getRtriangle that he really returns a right triangle

Console :

please help
 
Brian Burress
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Petr,



Check your classpath. Based on the error, it appears the JUnit jar is not defined properly in the classpath.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic