Category Archives: JavaCode

Automation Testing with Selenium IDE

Test automation means using a software tool to run repeatable tests against the application to be tested.

Selenium is a free (open source) automated testing suite for web applications across different browsers and platforms. Selenium is not just a single tool but a suite of softwares, each catering to different testing needs of an organization. It has four components.

  • Selenium Integrated Development Environment (IDE)
  • Selenium Remote Control (RC)
  • WebDriver
  • Selenium Grid

Many people get started with Selenium IDE. Using the IDE you can create simple tests quickly, sometimes within seconds.
Selenium IDE
– The tool you use to develop your test cases.
– Firefox plug-in

Download the tutorial document here: https://www.dropbox.com/s/855lit90esxbxm5/SeleniumIDE.zip

[Java] Compare two list

Problem:

I have two classes are Employee and Department


class Department{
private Long deptId;
private String deptName;

public Long getDeptId() {
return deptId;
}
public void setDeptId(Long deptId) {
this.deptId = deptId;
}
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
}

class Employee{
private Long empId;
private String empName;
private Department dept;

public Employee() {
super();
}

public Employee(Long empId, String empName, Department dept) {
super();
this.empId = empId;
this.empName = empName;
this.dept = dept;
}
public Long getEmpId() {
return empId;
}
public void setEmpId(Long empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public Department getDept() {
return dept;
}
public void setDept(Department dept) {
this.dept = dept;
}

}

And, I write  a class for compare two list with data from Employee class: ListComparisonTest


package tdd.sprint10;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.*;

public class ListComparisonTest {

private Department dept;

public ListComparisonTest() {
}

@Before
public void setUp() throws Exception {
dept=new Department();
}

@After
public void tearDown() throws Exception {
}

@Test
public void testCompareList() {
Employee emp1 = new Employee();
emp1.setEmpId(1L);
emp1.setEmpName("Van Huong");
emp1.setDept(dept);

Employee emp2 = new Employee();
emp2.setEmpId(2L);
emp2.setEmpName("Xuan Vinh");
emp2.setDept(dept);

List<Employee> firstList = new ArrayList<Employee>();
firstList.add(emp1);
firstList.add(emp2);

List<Employee> secondList = new ArrayList<Employee>();
secondList.add(new Employee(1L,"Van Huong",dept));
secondList.add(new Employee(2L,"Xuan Vinh",dept));

assertEquals(firstList.size(), secondList.size());
assertTrue(firstList.containsAll(secondList));
}

}

It’s fail when I  run the test class with JUnit Test!

The solution: create hashCode() and equals() functions on Employee class

On Eclipse IDE, press Alt + Shift + S, chose  generate and hashCode() and equals() functions.


@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((dept == null) ? 0 : dept.hashCode());
result = prime * result + ((empId == null) ? 0 : empId.hashCode());
result = prime * result + ((empName == null) ? 0 : empName.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Employee other = (Employee) obj;
if (dept == null) {
if (other.dept != null)
return false;
} else if (!dept.equals(other.dept))
return false;
if (empId == null) {
if (other.empId != null)
return false;
} else if (!empId.equals(other.empId))
return false;
if (empName == null) {
if (other.empName != null)
return false;
} else if (!empName.equals(other.empName))
return false;
return true;
}

Advanced programming

Tự học lập trình Android, android wear - lập trình smartwatch, Windows phone, Web service, C++, C#, java, Swift, Python, kotlin...

Tôi IT - Change the world

Research + Technical -> Programming,

juliansherman.net/

Building A Business While Having A Life

VN.NVANHUONG

No Pain No Gain

Study and Share's Blog

Việt Nam tươi đẹp...

Broly

One of the best way to learn is by writing to the paper.