how to write test case in java

0
0

hi
I created one class ABC.java,
and there is one constructor ABC() as follows:

 public class ABC {
private static String host;
private static String port;
------
public ABC(){
try {
File file = new File("Element.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);

I am passing Element.xml as a input,I want to test this class,so I created ABCTest class,
please tell me how to write test case for constructor ABC() and how to write assert(),for above code

  • You must to post comments
0
0

Although Selenium is a test tool itself, it sounds to me as if you want to test this class itself. Like implementing a test with jUNit.

With the snippet you just provided, there’s not much to test, because you don’t change the objects state (yet). The instance variables are not initialized (yet). The constructor does something but does not produce a result.

You could write a pretty small test case to check if there’s not Exception being thrown during initialization. Although this may be difficult, because you catch exceptions in the constructor.

And you may consider redirecting System.out to a string during the test and check if the code prints the expected output to the console.

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website