What is a concise way to test outputs of a function in java? -
is there easy way chain testable function calls concise block run , increment score when test comes positive? following class test.
public class weather{ public weather(float temp, int day, int month, int year){} public float gettemp(){} public void setcelsius(){} public void setfahrenheit(){} public boolean iscelsius(){} public string tostring(){} } a typical test case consists of setting celsius, , fahrenheit, getting value, , match string.
weather testme = new weather(100.6f, 31, 7, 1997); if(testme.tostring().equals("july 31, 1997. temperature 100.60 c.")) { score+=1} if(testme.gettemp() == 100.6f) {score+=1} if(testme.iscelcius()) {score+=1;} testme.setfahrenheit(); if(testme.tostring().equals("july 31, 1997. temperature 213.08 f.")) { score+=1} if(testme.gettemp() == 213.08f) {score+=1} if(!testme.iscelcius()) {score+=1;} testme.setcelcius(); if(testme.iscelcius()) {score+=1;} i repeat on , on again, can testing can shortened?
i think scoring system not right way measure correctness of code. test should have 2 states. passed or failed. scoring cannnot achieve this.
u can use junit test code. write possible test cases using junit , run test. know whether code passed or failed.
to start learning junit u can go throw basic tutorials this
Comments
Post a Comment