2

I am given a javascript function which takes as input some numbers and returns the max, as a part of a project at the university, and I have to test it, using Selenium, JUnit, Ant and JScover. I have seen some tutorials about each one individually(ant manual,JUnit Tutorial,Selenium tutorial) and I have understood that JScover just graphically presents you the results of the test.

However, I have difficulties understanding the difference between Selenium, JUnit and Ant. I also do not know how to start making test cases. I have eclipse installed, and I have the function, but how I am supposed to combine the three, and what I should do in each one?

Do you also know any example which uses those that can help me?

1
  • Look for Selenium tutorials in Java; most use JUnit, though they tend to use Maven instead of Ant. That can help with understanding how those two tools interact at least Commented Mar 6, 2014 at 16:11

2 Answers 2

8

Selenium is a tool that remote-controls a browser. You can use it to simulate a user interacting with a web site.

JUnit is a framework for writing Java unit tests. It takes some of the grunt work out of organizing tests and generating reports. You can express each test as a method on a class; typically, you have multiple tests per class. JUnit will run the tests for you and report which tests passed and which failed. If you need to write tests for a web site, you might use JUnit tests that call Selenium APIs.

Ant is a tool for building software. You describe a project in an XML file, and then Ant will use that description to build the software for you. For example, it might compile your Java source code into class files and then combine those class files with some HTML files and some Javascript files into a WAR file.

JScover is a tool for determining code coverage. A code coverage tool can help you understand which parts of your code are getting exercised by your tests.

0

we can simplify junit and selenium comparision as follow :--

  • Junit is used majorly to test server side/backend/Custom API unit testing, for ex: you make use of junit apis along with java code to test your backend logic by writing small parameteriasied method to check your code logic. Junit is also used with Selenium to automate everything.

     +++++++++++++++ **Sample Junit test Case** +++++++++++++++++++
     import org.junit.Test;
     import static org.junit.Assert.*;
     public class jUnitTestCase{
         @Test
         public void testConcatenation() {
             MyUnit myUnit = new performConcatenation();
             String result = myUnit.concatenate("A", "B");
             assertEquals("AB", result);
         }
     }
     +++++++++++++++ **Sample Custom API to be unit tested** +++++++++++++++
     public class performConcatenation{
         public String concatenate(String A, String B){
             return A+B;
         }
     }
    
  • Where as Selenium is a tool (.jar+exe) which you use and then write use case in terms of programming to invoke browser to automate UI testing.

+++++++++++++++ Sample Selenium test Case +++++++++++++++++++

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class LinkedInLogin {

public static void main(String[] args) {
          WebDriver driver=new ChromeDriver(); driver.manage().window().maximize(); 
          driver.get("https://www.linkedin.com/login"); 
          System.out.println("linked in invoked..............");
          WebElement username=driver.findElement(By.id("username")); 
          WebElement password=driver.findElement(By.id("password")); 
          WebElement login=driver.findElement(By.xpath("//button[text()='Sign in']")); 
          username.sendKeys("[email protected]"); password.sendKeys("your inkedIn Password"); 
          login.click(); String actualUrl="https://www.linkedin.com/feed/"; 
}

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.