Thắc mắc về junit trong java

Em có đoạn code hàm get sau nhưng kết quả toàn ra fail ạ

    public void testsalary()
    {
        float x=  3.0f;
        Teacher emplyx =new Teacher();
        assertEquals(x, emplyx.getSalary());
        
    }

hàm set/get của e đây ạ

package pro192xa4.entity;

import java.lang.reflect.Field;
import pro192xa4.business.AllowanceCalulator;

/**
 *
 * @author hp
 */
public class Teacher extends Employee {

    private String faculty;//khoa
    private EDegree degree;//trình độ
    private int teachingHours;//số tiết dạy

    public Teacher() {
        float allowance = AllowanceCalulator.calculateAllowance((this));
        this.setAllowance(allowance);
    }

    public String getFaculty() {
        return faculty;
    }

    public void setFaculty(String faculty) {
        this.faculty = faculty;
    }

    public EDegree getDegree() {
        return degree;
    }

    public void setDegree(EDegree degree) {
        this.degree = degree;
    }

    public int getTeachingHours() {
        return teachingHours;
    }

    public void setTeachingHours(int teachingHours) {
        this.teachingHours = teachingHours;
    }
    //sal=Hệ số lương*730+phụ cấp+số tiết dạy*45.
    @Override
    public float getSalary() {
        float sal;
        sal = this.getSalaryRatio() * 730 + this.getAllowance() + this.teachingHours * 45;
        return sal;
        
    }
    @Override
    public String toString(){
        return  "Teacher ," +
                this.getFullName()+", "+
                this.getFaculty()+", "+
                this.getDegree()+", "+
                Float.toString(this.getSalaryRatio())+", "+
                Float.toString(this.getAllowance())+", "+
                Float.toString(this.getTeachingHours())+", "+
                Float.toString(this.getSalary());                
    }
}
package pro192xa4.entity;

import java.lang.reflect.Field;
import pro192xa4.business.AllowanceCalulator;

/**
 *
 * @author hp
 */
public class Teacher extends Employee {

    private String faculty;//khoa
    private EDegree degree;//trình độ
    private int teachingHours;//số tiết dạy

    public Teacher() {
        float allowance = AllowanceCalulator.calculateAllowance((this));
        this.setAllowance(allowance);
    }

    public String getFaculty() {
        return faculty;
    }

    public void setFaculty(String faculty) {
        this.faculty = faculty;
    }

    public EDegree getDegree() {
        return degree;
    }

    public void setDegree(EDegree degree) {
        this.degree = degree;
    }

    public int getTeachingHours() {
        return teachingHours;
    }

    public void setTeachingHours(int teachingHours) {
        this.teachingHours = teachingHours;
    }
    //sal=Hệ số lương*730+phụ cấp+số tiết dạy*45.
    @Override
    public float getSalary() {
        float sal;
        sal = this.getSalaryRatio() * 730 + this.getAllowance() + this.teachingHours * 45;
        return sal;
        
    }
    @Override
    public String toString(){
        return  "Teacher ," +
                this.getFullName()+", "+
                this.getFaculty()+", "+
                this.getDegree()+", "+
                Float.toString(this.getSalaryRatio())+", "+
                Float.toString(this.getAllowance())+", "+
                Float.toString(this.getTeachingHours())+", "+
                Float.toString(this.getSalary());                
    }


}

hàm set/get của e đây ạ

Thì nó không bằng 3.0 nên mới thế.

ok bác em tìm được chỗ sai rồi ạ!

Em đã sửa được lỗi nhờ adm đóng topic cho em ạ !

2 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?