I am very new to android developing and recently did my first project. It is only a basic calculator with addition, subtraction, multiplication and division.
Now, I am looking to go into Unit testing using JUnits with KOTLIN. How should I go about doing this? I've been searching around and have no idea.
Calculator Java Codes:
package com.example.zhiwen.calculator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity{
Button plus,minus,times,divide;
TextView textview3;
EditText first, second;
double no1 = 0, no2 = 0;
double answer = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
plus = (Button) findViewById(R.id.plus);
minus = (Button) findViewById(R.id.minus);
times = (Button) findViewById(R.id.times);
divide = (Button) findViewById(R.id.divide);
textview3 = (TextView) findViewById(R.id.textview3);
first = (EditText) findViewById(R.id.editText);
second = (EditText) findViewById(R.id.editText2);
}
public void ClickMeButton(View view){
if(first.getText().toString().isEmpty() || second.getText().toString().isEmpty())
{
textview3.setText("Answer: -");
Toast.makeText(getApplicationContext(),"Please fill up both numbers",Toast.LENGTH_SHORT).show();
}
else
{
no1 = Integer.parseInt(first.getText().toString());
no2 = Integer.parseInt(second.getText().toString());
textview3.setText("Answer: " + Functions.addFunction(no1,no2));
}
}
public void ClickMeButton2(View view){
if(first.getText().toString().isEmpty() || second.getText().toString().isEmpty())
{
textview3.setText("Answer: -");
Toast.makeText(getApplicationContext(),"Please fill up both numbers",Toast.LENGTH_SHORT).show();
}
else
{
no1 = Integer.parseInt(first.getText().toString());
no2 = Integer.parseInt(second.getText().toString());
textview3.setText("Answer: " + Functions.minusFunction(no1,no2));
}
}
public void ClickMeButton3(View view){
if(first.getText().toString().isEmpty() || second.getText().toString().isEmpty())
{
textview3.setText("Answer: -");
Toast.makeText(getApplicationContext(),"Please fill up both numbers",Toast.LENGTH_SHORT).show();
}
else
{
no1 = Integer.parseInt(first.getText().toString());
no2 = Integer.parseInt(second.getText().toString());
textview3.setText("Answer: " + Functions.multiFunction(no1,no2));
}
}
public void ClickMeButton4(View view){
if(first.getText().toString().isEmpty() || second.getText().toString().isEmpty())
{
textview3.setText("Answer: -");
Toast.makeText(getApplicationContext(),"Please fill up both numbers",Toast.LENGTH_SHORT).show();
}
else
{
no1 = Integer.parseInt(first.getText().toString());
no2 = Integer.parseInt(second.getText().toString());
textview3.setText("Answer: " + Functions.divFunction(no1,no2));
}
}
}
Function Class Codes:
package com.example.zhiwen.calculator;
/**
* Created by Zhiwen on 5/25/2017.
*/
public class Functions {
public static double addFunction(double no1, double no2){
double answer;
answer = no1 + no2;
return answer;
}
public static double minusFunction(double no1, double no2){
double answer;
answer = no1 - no2;
return answer;
}
public static double multiFunction(double no1, double no2){
double answer;
answer = no1 * no2;
return answer;
}
public static double divFunction(double no1, double no2){
double answer;
answer = no1 / no2;
return answer;
}
}