61 lines
2.0 KiB
Java
61 lines
2.0 KiB
Java
package org.aplas.myshop;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
import androidx.appcompat.widget.AppCompatButton;
|
|
import androidx.lifecycle.Lifecycle;
|
|
import androidx.test.core.app.ActivityScenario;
|
|
|
|
import org.aplas.myshop.sql.Database;
|
|
import org.junit.After;
|
|
import org.junit.Before;
|
|
import org.junit.FixMethodOrder;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runners.MethodSorters;
|
|
import org.robolectric.RobolectricTestRunner;
|
|
import org.robolectric.annotation.Config;
|
|
|
|
import com.google.android.material.textfield.TextInputEditText;
|
|
|
|
@RunWith(RobolectricTestRunner.class)
|
|
@Config(manifest= Config.NONE)
|
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
|
|
|
public class TestAddProductSuccess extends ViewTest{
|
|
ActivityScenario<AddProductActivity> scenario;
|
|
private TextInputEditText nama, price;
|
|
private AppCompatButton addButton;
|
|
private Database database;
|
|
|
|
@Before
|
|
public void setUp() {
|
|
scenario = ActivityScenario.launch(AddProductActivity.class);
|
|
scenario.moveToState(Lifecycle.State.CREATED);
|
|
scenario.onActivity(activity -> {
|
|
nama = activity.findViewById(R.id.textInputEditTextProductName);
|
|
price = activity.findViewById(R.id.textInputEditTextProductPrice);
|
|
addButton = activity.findViewById(R.id.appCompatButtonAddProduct);
|
|
database = new Database(activity);
|
|
});
|
|
}
|
|
|
|
@After
|
|
public void tearDown() {
|
|
scenario.close();
|
|
database.close();
|
|
}
|
|
|
|
@Test
|
|
public void test_01_addProduct() {
|
|
scenario.onActivity(activity -> {
|
|
nama.setText("Product Example");
|
|
price.setText("15000");
|
|
addButton.performClick();
|
|
boolean x = database.checkProduct("Product Example", "15000");
|
|
|
|
testItem(true, x, "Your add product function doesn't seem working, please check the add button on click function inside AddProductActivity, or check the database add product method inside the database class", 3);
|
|
});
|
|
}
|
|
}
|