0

I am working on a small python desktop project, which can calculate the human BMI (BMI is your weight ver your height squared). My application works fine, but I have no idea how to write a unit test for it.

Here is the part of my code (the main function) I want to test:

from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import math

class MY_BMI_Calculator:
    def __init__(self,master):
    master.title('BMI Calculator')
    def calculate_BMI(self):
        self.inchs = int(self.entry_ft.get())* 12 + int(self.entry_in.get())
        self.BMI = int(self.entry_weight.get())* 703 /math.pow(self.inchs,2)
        return  round(self.BMI,1)
Zichen Ma
  • 907
  • 3
  • 14
  • 30
  • https://docs.python.org/3/library/unittest.html#basic-example, http://stackoverflow.com/questions/4083796/how-do-i-run-unittest-on-a-tkinter-app – Ilja Everilä Jun 14 '16 at 06:11
  • 5
    Right now your GUI and logic to compute BMI is tightly coupled. I'd suggest decoupling it. Extracting function `bmi(height, weight)` which returns bmi value may be a good place to start. – Łukasz Rogalski Jun 14 '16 at 06:15
  • Maybe also correct the indent on the line `master.title('BMI Calculator')`, as this should make the Python stop interpreting the code ... – Dilettant Jun 14 '16 at 10:34

0 Answers0