How to create a test class with a test method in JUnit to testing framework?

0 votes
How to create a test class with a test method in JUnit to testing framework?
Jun 12 in Selenium by Sargun
15 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Hi Sargun, first we need to create a test class with a test method annotated with @Test as given below:

FirstClassTest.java

package testingDemo.JUnit;  

import static org.JUnit.Assert.*;
import org.JUnit.Test;
public class FirstClassTest {
    @Test
    public void FirstMethod(){
        String str= "JUnit is working fine";
        assertEquals("JUnit is working fine",str);
    }
}

To execute our above test method ,we need to create a test runner. In the test runner we have to add test class as a parameter in JUnitCore's runclasses() method . It will return the test result, based on whether the test is passed or failed:

package testingDemo.JUnit;		

import org.JUnit.runner.JUnitCore;		
import org.JUnit.runner.Result;		
import org.JUnit.runner.notification.Failure;		

public class TestRunner {				
			public static void main(String[] args) {									
            Result result = JUnitCore.runClasses(MyFirstClassTest.class);					
			for (Failure failure : result.getFailures()) {							
              System.out.println(failure.toString());					
      }		
      System.out.println("Result=="+result.wasSuccessful());							
   }		
}
answered Jun 12 by Nagendra

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

How to open a browser window in full screen using Selenium WebDriver with C#

Simply Use this: driver.Manage().Window.Maximize(); READ MORE

answered Jun 7, 2018 in Selenium by Samarpit
• 5,130 points
2,218 views
0 votes
1 answer

How to replace remote resources with local resource in a page with Selenium?

You could change URL for that script ...READ MORE

answered Aug 8, 2018 in Selenium by Samarpit
• 5,130 points
20 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
142 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
532 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
134 views
0 votes
1 answer
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.