create: new folder
This commit is contained in:
parent
a461062153
commit
6d562d2f0d
291
ElementTest.java
Normal file
291
ElementTest.java
Normal file
|
|
@ -0,0 +1,291 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.graphics.drawable.GradientDrawable;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Adapter;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RadioButton;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
import android.widget.TableLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ElementTest extends org.aplas.myshop.ViewTest {
|
||||||
|
private View component;
|
||||||
|
private String compName;
|
||||||
|
private String msgHeader;
|
||||||
|
private String className;
|
||||||
|
//private ArrayList<HashMap> testList = new ArrayList<>();
|
||||||
|
|
||||||
|
public ElementTest(View comp) {
|
||||||
|
component =comp;
|
||||||
|
compName = component.getContext().getResources().getResourceEntryName(component.getId());
|
||||||
|
className = component.getClass().getSimpleName();
|
||||||
|
msgHeader = "\n( "+compName+" - "+className+" ) ";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIdName(String expected) {
|
||||||
|
String msg = msgHeader + "Element Id Name is not suitable\n";
|
||||||
|
testItem(expected,compName,msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWidth(int expected) {
|
||||||
|
String msg = msgHeader + "Element width is not suitable\n";
|
||||||
|
testItem(expected,component.getLayoutParams().width,msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testHeight(int expected) {
|
||||||
|
String msg = msgHeader + "Element height is not suitable\n";
|
||||||
|
testItem(expected,component.getLayoutParams().height,msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWeight(float expected) {
|
||||||
|
String msg = msgHeader + "Element height is not suitable\n";
|
||||||
|
testItem(expected,((LinearLayout.LayoutParams)component.getLayoutParams()).weight,msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testOrientation(int expected) {
|
||||||
|
String msg = msgHeader + "Element orientation is not suitable\n";
|
||||||
|
testItem(expected,((LinearLayout)component).getOrientation(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testTopMargin(int expected) {
|
||||||
|
String msg = msgHeader + "Element top margin is not suitable\n";
|
||||||
|
if (component.getLayoutParams().getClass().equals(RelativeLayout.LayoutParams.class)) {
|
||||||
|
testItem(expected,((RelativeLayout.LayoutParams)component.getLayoutParams()).topMargin,msg,1);
|
||||||
|
} else {
|
||||||
|
testItem(expected, ((LinearLayout.LayoutParams) component.getLayoutParams()).topMargin, msg, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBottomMargin(int expected) {
|
||||||
|
String msg = msgHeader + "Element top margin is not suitable\n";
|
||||||
|
if (component.getLayoutParams().getClass().equals(RelativeLayout.LayoutParams.class)) {
|
||||||
|
testItem(expected,((RelativeLayout.LayoutParams)component.getLayoutParams()).bottomMargin,msg,1);
|
||||||
|
} else {
|
||||||
|
testItem(expected, ((LinearLayout.LayoutParams) component.getLayoutParams()).bottomMargin, msg, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPaddingLeft(int expected) {
|
||||||
|
String msg = msgHeader + "Element left padding is not suitable\n";
|
||||||
|
testItem(expected,component.getPaddingLeft(),msg,1);
|
||||||
|
}
|
||||||
|
public void testPaddingRight(int expected) {
|
||||||
|
String msg = msgHeader + "Element right padding is not suitable\n";
|
||||||
|
testItem(expected,component.getPaddingRight(),msg,1);
|
||||||
|
}
|
||||||
|
public void testPadding(int expected) {
|
||||||
|
String msg = msgHeader + "Element padding is not suitable\n";
|
||||||
|
testItem(expected,component.getPaddingTop(),msg,1);
|
||||||
|
testItem(expected,component.getPaddingBottom(),msg,1);
|
||||||
|
testItem(expected,component.getPaddingLeft(),msg,1);
|
||||||
|
testItem(expected,component.getPaddingRight(),msg,1);
|
||||||
|
}
|
||||||
|
public void testBgColor(int expected) {
|
||||||
|
String msg = msgHeader + "Element Background color is not suitable\n";
|
||||||
|
testItem(expected,((ColorDrawable) component.getBackground()).getColor(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBgGradientColor(int[] expected) {
|
||||||
|
String msg = msgHeader + "Element Background gradient color is not suitable\n";
|
||||||
|
GradientDrawable draw = (GradientDrawable) component.getBackground();
|
||||||
|
//draw.getColors()
|
||||||
|
testItem(expected[0],draw.getColors()[0],msg,1);
|
||||||
|
testItem(expected[1],draw.getColors()[1],msg,1);
|
||||||
|
testItem(expected[2],draw.getColors()[2],msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testTextString(String expected) {
|
||||||
|
String msg = msgHeader + "Element text string is not suitable\n";
|
||||||
|
testItem(expected,((TextView)component).getText().toString(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testTextFace(Typeface expected) {
|
||||||
|
String msg = msgHeader + "Element text font is not suitable\n";
|
||||||
|
testItem(expected,((TextView)component).getPaint().getTypeface(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testTextStyle(int expected) {
|
||||||
|
String msg = msgHeader + "Element text style (bold/italic/normal) is not suitable\n";
|
||||||
|
testItem(expected,((TextView)component).getPaint().getTypeface().getStyle(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testTextColor(int expected) {
|
||||||
|
String msg = msgHeader + "Element text color is not suitable\n";
|
||||||
|
testItem(expected,((TextView)component).getTextColors().getDefaultColor(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testTextSize(float expected) {
|
||||||
|
String msg = msgHeader + "Element text size is not suitable\n";
|
||||||
|
/*if (className.equals("AppCompatSpinner")) {
|
||||||
|
testItem(expected,((Spinner)component).get,msg,1);
|
||||||
|
}*/
|
||||||
|
testItem(expected,((TextView)component).getTextSize(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGravity(int expected) {
|
||||||
|
String msg = msgHeader + "Element gravity orientation is not suitable\n";
|
||||||
|
if (className.equals("AppCompatSpinner")) {
|
||||||
|
testItem(expected,((Spinner)component).getGravity(),msg,1);
|
||||||
|
} else if (className.equals("AppCompatTextView")) {
|
||||||
|
testItem(expected, ((TextView) component).getGravity(), msg, 1);
|
||||||
|
} else if (className.equals("TableLayout")) {
|
||||||
|
testItem(expected, ((LinearLayout)component).getGravity(), msg, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllCaps(boolean expected) {
|
||||||
|
String msg = msgHeader + "Element all caps is not suitable\n";
|
||||||
|
testItem(expected,((TextView)component).isAllCaps(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testHintText(String expected) {
|
||||||
|
String msg = msgHeader + "Element hint text is not suitable\n";
|
||||||
|
testItem(expected,((TextView)component).getHint().toString(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testInputType(int expected) {
|
||||||
|
String msg = msgHeader + "Element input type is not suitable\n";
|
||||||
|
testItem(expected,((TextView)component).getInputType(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIsEnabled(boolean expected) {
|
||||||
|
String msg = msgHeader + "Element enabled value is not suitable\n";
|
||||||
|
testItem(expected,component.isEnabled(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPromptText(String expected) {
|
||||||
|
String msg = msgHeader + "Element prompt text is not suitable\n";
|
||||||
|
testItem(expected,((Spinner)component).getPrompt().toString(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSpinnerMode(int expected) {
|
||||||
|
String msg = msgHeader + "Element mode is not suitable\n";
|
||||||
|
if (expected==0) {
|
||||||
|
testItem(expected,((Spinner)component).getDropDownVerticalOffset(),msg,1);
|
||||||
|
} else {
|
||||||
|
testItem(expected,((Spinner)component).getDropDownVerticalOffset()>0,msg,3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSpinnerContent(List expected) {
|
||||||
|
String msg = msgHeader + "Element spinner content is not suitable\n";
|
||||||
|
|
||||||
|
Adapter list = ((Spinner)component).getAdapter();
|
||||||
|
String res = "";
|
||||||
|
for (int i=0; i<list.getCount(); i++){
|
||||||
|
res += list.getItem(i)+";";
|
||||||
|
/*
|
||||||
|
if (!expected.get(i).equals(list.getItem(i))) {
|
||||||
|
isValid = false;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
testItem(listToString(expected),res,msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSpinnerContentUnordered(List expected) {
|
||||||
|
String msg = msgHeader + "Spinner's content is not correct\n";
|
||||||
|
|
||||||
|
Adapter list = ((Spinner)component).getAdapter();
|
||||||
|
//String res = "";
|
||||||
|
for (int i=0; i<list.getCount(); i++){
|
||||||
|
//res += list.getItem(i)+";";
|
||||||
|
testItem(null, expected.contains(list.getItem(i)),msg,3);
|
||||||
|
}
|
||||||
|
//testItem(listToString(expected),res,msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelectedSpinnerItem() {
|
||||||
|
Adapter list = ((Spinner)component).getAdapter();
|
||||||
|
/* String res = "";
|
||||||
|
for (int i=0; i<list.getCount(); i++){
|
||||||
|
res += list.getItem(i)+";";
|
||||||
|
testItem(null, expected.contains(list.getItem(i)),msg,3);
|
||||||
|
}*/
|
||||||
|
return (String) list.getItem(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSpinnerContent(String[] expected) {
|
||||||
|
/*
|
||||||
|
String msg = msgHeader + "Element spinner content is not suitable\n";
|
||||||
|
//testItem(expected,((Spinner)component).getGravity(),msg,1);
|
||||||
|
Adapter list = ((Spinner)component).getAdapter();
|
||||||
|
boolean isValid = true;
|
||||||
|
for (int i=0; i<list.getCount(); i++){
|
||||||
|
if (!expected[i].equals(list.getItem(i))) {
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
testItem(true,isValid,msg,1);
|
||||||
|
*/
|
||||||
|
String msg = msgHeader + "Element spinner content is not suitable\n";
|
||||||
|
|
||||||
|
Adapter list = ((Spinner)component).getAdapter();
|
||||||
|
String res = "";
|
||||||
|
for (int i=0; i<list.getCount(); i++){
|
||||||
|
res += list.getItem(i)+";";
|
||||||
|
}
|
||||||
|
testItem(arrayToString(expected),res,msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSpinnerContent(String expected) {
|
||||||
|
testSpinnerContent(expected.split("\\,"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSelected(boolean expected) {
|
||||||
|
String msg = msgHeader + "Element checked/selected value is not suitable\n";
|
||||||
|
if (component.getClass().equals(androidx.appcompat.widget.AppCompatCheckBox.class)) {
|
||||||
|
testItem(expected,((CheckBox)component).isChecked(),msg,1);
|
||||||
|
} else {
|
||||||
|
testItem(expected,((RadioButton)component).isChecked(),msg,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testImageSrc(String expected) {
|
||||||
|
String msg = msgHeader + "Element image source is not suitable\n";
|
||||||
|
//int resId = R.font.cambria;
|
||||||
|
int resId = component.getContext().getResources().getIdentifier(expected, "drawable",component.getContext().getPackageName());
|
||||||
|
testItem(expected,component.getResources().getResourceEntryName(resId),msg,1);
|
||||||
|
//int resId = (Integer) component.gett
|
||||||
|
// testItem(0,resId,msg,1);
|
||||||
|
//testItem(expected,component.getResources().getResourceEntryName(resId),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testLayoutBelow(int expected) {
|
||||||
|
String msg = msgHeader + "Element layout below is not suitable\n";
|
||||||
|
RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams)component.getLayoutParams();
|
||||||
|
testItem(expected, para.getRule(3), msg, 1); //check android:layout_below
|
||||||
|
//para.get
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testLinearHorizontal(boolean expected) {
|
||||||
|
String msg = msgHeader + "Element layout center horizontal is not suitable\n";
|
||||||
|
RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams)component.getLayoutParams();
|
||||||
|
int val = (expected)?-1:0;
|
||||||
|
/*int val=0;
|
||||||
|
int idx=0;
|
||||||
|
for (int i=0; i<para.getRules().length; i++){
|
||||||
|
if (para.getRule(i)!=0) {
|
||||||
|
val=para.getRule(i);
|
||||||
|
idx=i;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
testItem(val, para.getRule(14), msg, 1); //check android:layout_below
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStrectchColumn(boolean expected) {
|
||||||
|
String msg = msgHeader + "Element column strecth is not suitable\n";
|
||||||
|
testItem(expected,((TableLayout)component).isStretchAllColumns(),msg,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testVisibility(int visibility) {
|
||||||
|
String msg = msgHeader + "Element visibility is not suitable\n";
|
||||||
|
testItem(visibility,component.getVisibility(),msg,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
17
ExampleUnitTest.java
Normal file
17
ExampleUnitTest.java
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example local unit test, which will execute on the development machine (host).
|
||||||
|
*
|
||||||
|
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||||
|
*/
|
||||||
|
public class ExampleUnitTest {
|
||||||
|
@Test
|
||||||
|
public void addition_isCorrect() {
|
||||||
|
assertEquals(4, 2 + 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
GUIDE1-11/C2.01 Guide--.docx
Normal file
BIN
GUIDE1-11/C2.01 Guide--.docx
Normal file
Binary file not shown.
BIN
GUIDE1-11/C2.02 Guide--.docx
Normal file
BIN
GUIDE1-11/C2.02 Guide--.docx
Normal file
Binary file not shown.
BIN
GUIDE1-11/C2.03 Guide--.docx
Normal file
BIN
GUIDE1-11/C2.03 Guide--.docx
Normal file
Binary file not shown.
BIN
GUIDE1-11/C2.04 Guide--.docx
Normal file
BIN
GUIDE1-11/C2.04 Guide--.docx
Normal file
Binary file not shown.
BIN
GUIDE1-11/C2.05 Guide--.docx
Normal file
BIN
GUIDE1-11/C2.05 Guide--.docx
Normal file
Binary file not shown.
BIN
GUIDE1-11/C2.06 Guide--.docx
Normal file
BIN
GUIDE1-11/C2.06 Guide--.docx
Normal file
Binary file not shown.
BIN
GUIDE1-11/C2.07 Guide--.docx
Normal file
BIN
GUIDE1-11/C2.07 Guide--.docx
Normal file
Binary file not shown.
BIN
GUIDE1-11/C2.08 Guide--.docx
Normal file
BIN
GUIDE1-11/C2.08 Guide--.docx
Normal file
Binary file not shown.
BIN
GUIDE1-11/C2.09 Guide--.docx
Normal file
BIN
GUIDE1-11/C2.09 Guide--.docx
Normal file
Binary file not shown.
BIN
GUIDE1-11/C2.10 Guide--.docx
Normal file
BIN
GUIDE1-11/C2.10 Guide--.docx
Normal file
Binary file not shown.
BIN
GUIDE1-11/C2.11 Guide--.docx
Normal file
BIN
GUIDE1-11/C2.11 Guide--.docx
Normal file
Binary file not shown.
BIN
GuideFiles.rar
BIN
GuideFiles.rar
Binary file not shown.
146
ResourceTest.java
Normal file
146
ResourceTest.java
Normal file
|
|
@ -0,0 +1,146 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ResourceTest extends org.aplas.myshop.ViewTest {
|
||||||
|
private Resources resource;
|
||||||
|
|
||||||
|
public ResourceTest(Resources rsc) {
|
||||||
|
resource =rsc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getResourceId(String name, String type) {
|
||||||
|
return resource.getIdentifier(name, type, getClass().getPackage().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStringResource(String name) {
|
||||||
|
int resId = getResourceId(name,"string");
|
||||||
|
testItem(0,resId,"String \'"+name+"\' is not defined in strings.xml of values resource",2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStringResource(String name, String expected) {
|
||||||
|
int resId = resource.getIdentifier(name, "string", getClass().getPackage().getName());
|
||||||
|
testItem(0,resId,"String \'"+name+"\' is not defined in strings.xml of values resource",2);
|
||||||
|
testItem(expected,resource.getString(resId),"Value of string \'"+name+"\' is not valid",1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIntegerResource(String name, int expected) {
|
||||||
|
int resId = resource.getIdentifier(name, "integer", getClass().getPackage().getName());
|
||||||
|
testItem(0,resId,"Integer "+name+" id is not exist",2);
|
||||||
|
testItem(expected,resource.getString(resId),"Integer "+name+" value is not valid",1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStringArrayResource(String name, String[] expected) {
|
||||||
|
int resId = resource.getIdentifier(name, "array", getClass().getPackage().getName());
|
||||||
|
testItem(0,resId,"String array \'"+name+"\' is not defined in strings.xml of values resource",2);
|
||||||
|
String[] str = resource.getStringArray(resId);
|
||||||
|
testItem(arrayToString(expected),arrayToString(str),"Value of String array \'"+name+"\' is not valid",1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testColorResource(Activity activity, String name, String value) {
|
||||||
|
int resId = resource.getIdentifier(name, "color", getClass().getPackage().getName());
|
||||||
|
testItem(0,resId,"Color '"+name+"' is not defined in colors.xml of value resource",2);
|
||||||
|
int clrVal = ContextCompat.getColor(activity, resId);
|
||||||
|
//testItem(Color.parseColor(value),clrVal,"Color '"+name+"' value should be '"+value+"'",1);
|
||||||
|
testItem(value.toUpperCase(),getHexColor(clrVal),"Color '"+name+"' value should be '"+value+"'",1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testColorArrayResource(String name, String[] expected) {
|
||||||
|
int resId = resource.getIdentifier(name, "array", getClass().getPackage().getName());
|
||||||
|
testItem(0,resId,"Color array \'"+name+"\' is not defined in colors.xml of values resource",2);
|
||||||
|
int[] str = resource.getIntArray(resId);
|
||||||
|
testItem(arrayToString(expected),colorArrayToString(str),
|
||||||
|
"Value of Color array \'"+name+"\' is not valid in colors.xml resource",1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testFontResource(String name, String expected) {
|
||||||
|
//int resId = R.font.cambria;
|
||||||
|
//Typeface font = Typeface.createFromAsset(resource.getAssets(),name);
|
||||||
|
int resId = resource.getIdentifier(name, "font", getClass().getPackage().getName());
|
||||||
|
testItem(0,resId,"Font "+name+" id is not exist",2);
|
||||||
|
testItem(expected,resource.getResourceEntryName(resId),"Font "+name+" value is not valid",1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testImgResource(String name) {
|
||||||
|
int resId = resource.getIdentifier(name, "drawable", getClass().getPackage().getName());
|
||||||
|
testItem(0,resId,"Image "+name+".(png/jpg) is not exist in drawable resource ",2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testImgAnimationResource(String name) {
|
||||||
|
int resId = resource.getIdentifier(name, "drawable", getClass().getPackage().getName());
|
||||||
|
testItem(0,resId,"Image animation "+name+".xml is not exist in drawable resource ",2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testViewAnimationResource(String name) {
|
||||||
|
int resId = resource.getIdentifier(name, "anim", getClass().getPackage().getName());
|
||||||
|
testItem(0,resId,"View animation "+name+".xml is not exist in anim resource ",2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDrawableResource(String name, String expected) {
|
||||||
|
int resId = resource.getIdentifier(name, "drawable", getClass().getPackage().getName());
|
||||||
|
testItem(0,resId,"Drawable "+name+" id is not exist",2);
|
||||||
|
//testItem(expected,resource.getDrawable(resId).,"Drawable "+expected+" value is not valid",1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStyleResource(String name) {
|
||||||
|
int resId = resource.getIdentifier(name, "style", getClass().getPackage().getName());
|
||||||
|
testItem(0,resId,"Style '"+name+"' is not exist in styles.xml",2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testVideoResource(String name) {
|
||||||
|
int resId = resource.getIdentifier(name, "raw", getClass().getPackage().getName());
|
||||||
|
testItem(0,resId,"Video '"+name+".(mp4/mpg)' is not exist in raw folder of resource",2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAppTheme(Activity activity, String name) {
|
||||||
|
int resId = resource.getIdentifier(name, "style", getClass().getPackage().getName());
|
||||||
|
testItem(resId,activity.getApplicationInfo().theme,
|
||||||
|
"Applied theme in AndroidManifest.xml should be \'@style/"+name+"\'",1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAppPermission(Activity activity, String name) {
|
||||||
|
try {
|
||||||
|
PackageInfo info = activity.getPackageManager().getPackageInfo(activity.getPackageName(), PackageManager.GET_PERMISSIONS);
|
||||||
|
String[] permissions = info.requestedPermissions;
|
||||||
|
|
||||||
|
testItem(0,permissions.length>0,"Can't find 'uses-permission' in AndroidManifest.xml file",3);
|
||||||
|
int x = Arrays.asList(permissions).indexOf(name);
|
||||||
|
testItem(0, x>=0, "AndroidManifest.xml must contain permission value '"+name+"'\n"+
|
||||||
|
"put <uses-permission android:name=\""+name+"\" /> ",3);
|
||||||
|
} catch (Exception e) {
|
||||||
|
testItem(0,0,"Permission value in AndroidManifest.xml error",2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAppActivities(Activity activity, String name, String packName) {
|
||||||
|
//testItem(0,activity.getPackageManager().getLaunchIntentForPackage(packName+"."+name),
|
||||||
|
// "Activity "+name+" must be LAUNCHER",6);
|
||||||
|
|
||||||
|
try {
|
||||||
|
PackageInfo info = activity.getPackageManager().getPackageInfo(activity.getPackageName(), PackageManager.GET_INTENT_FILTERS);
|
||||||
|
ActivityInfo[] activities = info.activities;
|
||||||
|
|
||||||
|
String res="";
|
||||||
|
for (int i=0; i<activities.length; i++) {
|
||||||
|
res+=activities[i].name+"-"+activities[i].applicationInfo.category+"-"+activities[i].processName+"@";
|
||||||
|
}
|
||||||
|
testItem(0,0,res,2);
|
||||||
|
//testItem(0,permissions.length>0,"Can't find 'uses-permission' in AndroidManifest.xml file",3);
|
||||||
|
//int x = Arrays.asList(permissions).indexOf(name);
|
||||||
|
//testItem(0, x>=0, "AndroidManifest.xml must contain permission value '"+name+"'\n"+
|
||||||
|
// "put <uses-permission android:name=\""+name+"\" /> ",3);
|
||||||
|
} catch (Exception e) {
|
||||||
|
testItem(0,0,"Permission value in AndroidManifest.xml error"+e.toString(),2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
81
Suplement File/item_buyer_product_recycler.xml
Normal file
81
Suplement File/item_buyer_product_recycler.xml
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="5dp"
|
||||||
|
android:elevation="8dp"
|
||||||
|
app:cardCornerRadius="4dp">
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/list_item"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="#FFFFFF"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:padding="12dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
android:background="#FFFFFF"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginRight="12dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ProductID"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="product id"
|
||||||
|
android:textColor="#212121"
|
||||||
|
android:textSize="14dp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ProductName"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/hint_product_name"
|
||||||
|
android:textColor="#212121"
|
||||||
|
android:textSize="14dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ProductPrice"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:text="@string/hint_product_price"
|
||||||
|
android:textColor="#212121"
|
||||||
|
android:textSize="14dp" />
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/TextButton"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:background="#4CAF50"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="DETAIL PRODUCT"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="14dp" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
161
Suplement File/item_cart_recycler.xml
Normal file
161
Suplement File/item_cart_recycler.xml
Normal file
|
|
@ -0,0 +1,161 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="5dp"
|
||||||
|
android:elevation="8dp"
|
||||||
|
app:cardCornerRadius="4dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="3dp"
|
||||||
|
android:id="@+id/list_cart"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:weightSum="2">
|
||||||
|
|
||||||
|
<!--text view for our course tracks-->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:text="Product Buyer"
|
||||||
|
android:textColor="@color/black" />
|
||||||
|
|
||||||
|
|
||||||
|
<!--text view for our course duration-->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ProductBuyer"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:text="buyer"
|
||||||
|
android:textColor="@color/black" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:weightSum="2">
|
||||||
|
|
||||||
|
<!--text view for our course tracks-->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:text="Cart Id"
|
||||||
|
android:textColor="@color/black" />
|
||||||
|
|
||||||
|
|
||||||
|
<!--text view for our course duration-->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/CartID"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:text="ID"
|
||||||
|
android:textColor="@color/black" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:weightSum="2">
|
||||||
|
|
||||||
|
<!--text view for our course tracks-->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:text="Product Name"
|
||||||
|
android:textColor="@color/black" />
|
||||||
|
|
||||||
|
|
||||||
|
<!--text view for our course duration-->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ProductName"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:text="Name"
|
||||||
|
android:textColor="@color/black" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:weightSum="2">
|
||||||
|
|
||||||
|
<!--text view for our course tracks-->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:text="Product Price"
|
||||||
|
android:textColor="@color/black" />
|
||||||
|
|
||||||
|
|
||||||
|
<!--text view for our course duration-->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ProductPrice"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:text="Price"
|
||||||
|
android:textColor="@color/black" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:weightSum="2">
|
||||||
|
|
||||||
|
<!--text view for our course tracks-->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:text="Quantity"
|
||||||
|
android:textColor="@color/black" />
|
||||||
|
|
||||||
|
|
||||||
|
<!--text view for our course duration-->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/Quantity"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:text="Quantity"
|
||||||
|
android:textColor="@color/black" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
91
Suplement File/item_product_recycler.xml
Normal file
91
Suplement File/item_product_recycler.xml
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="5dp"
|
||||||
|
android:elevation="8dp"
|
||||||
|
app:cardCornerRadius="4dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/list_item"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="#FFFFFF"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:padding="12dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
android:background="#FFFFFF"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginRight="12dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ProductID"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="product id"
|
||||||
|
android:textColor="#212121"
|
||||||
|
android:textSize="14dp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ProductName"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/hint_product_name"
|
||||||
|
android:textColor="#212121"
|
||||||
|
android:textSize="14dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ProductPrice"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:text="@string/hint_product_price"
|
||||||
|
android:textColor="#212121"
|
||||||
|
android:textSize="14dp" />
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/TextButton"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:background="#4CAF50"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="DETAIL PRODUCT"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="14dp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/ButtonDelete"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:background="#673AB7"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="Delete"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 22 KiB |
76
TestAddProductFail.java
Normal file
76
TestAddProductFail.java
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import androidx.appcompat.widget.AppCompatButton;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestAddProductFail extends ViewTest{
|
||||||
|
ActivityScenario<AddProductActivity> scenario;
|
||||||
|
private TextInputLayout namaLayout, priceLayout;
|
||||||
|
private TextInputEditText nama, price;
|
||||||
|
private AppCompatButton addButton;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
scenario = ActivityScenario.launch(AddProductActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
namaLayout = activity.findViewById(R.id.textInputLayoutProductName);
|
||||||
|
priceLayout = activity.findViewById(R.id.textInputLayoutProductPrice);
|
||||||
|
nama = activity.findViewById(R.id.textInputEditTextProductName);
|
||||||
|
price = activity.findViewById(R.id.textInputEditTextProductPrice);
|
||||||
|
addButton = activity.findViewById(R.id.appCompatButtonAddProduct);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
scenario.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_01_emptyName() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama.setText("");
|
||||||
|
price.setText("100000");
|
||||||
|
addButton.performClick();
|
||||||
|
|
||||||
|
String expectedErrorMessage = "Enter Product Name";
|
||||||
|
assertNotNull("The text layout should throw error when product name is empty, please check your input validation inside AddProductActivity and make sure it has the same error message according to guide file", namaLayout.getError());
|
||||||
|
String actualErrorMessage = namaLayout.getError().toString();
|
||||||
|
testItem(expectedErrorMessage, actualErrorMessage, "Error message does not match, please check your input validation inside AddProductActivity and make sure it has the same error message according to guide file", 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_02_emptyPrice() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama.setText("Product");
|
||||||
|
price.setText("");
|
||||||
|
addButton.performClick();
|
||||||
|
|
||||||
|
String expectedErrorMessage = "Enter Product Price";
|
||||||
|
assertNotNull("The text layout should throw error when product price is empty, please check your input validation inside AddProductActivity and make sure it has the same error message according to guide file", priceLayout.getError());
|
||||||
|
String actualErrorMessage = priceLayout.getError().toString();
|
||||||
|
testItem(expectedErrorMessage, actualErrorMessage, "Error message does not match, please check your input validation inside AddProductActivity and make sure it has the same error message according to guide file", 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
60
TestAddProductSuccess.java
Normal file
60
TestAddProductSuccess.java
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
137
TestAddProducttoCart.java
Normal file
137
TestAddProducttoCart.java
Normal file
|
|
@ -0,0 +1,137 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import androidx.appcompat.widget.AppCompatButton;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
import org.aplas.myshop.adapters.ProductsRecyclerAdapter;
|
||||||
|
import org.aplas.myshop.model.Product;
|
||||||
|
import org.aplas.myshop.model.User;
|
||||||
|
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.Robolectric;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.Shadows;
|
||||||
|
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 TestAddProducttoCart extends ViewTest{
|
||||||
|
ActivityScenario<LoginActivity> scenario;
|
||||||
|
private EditText nama, password;
|
||||||
|
private Button loginButton;
|
||||||
|
private Database database;
|
||||||
|
private User user;
|
||||||
|
private Product product;
|
||||||
|
private RecyclerView recyclerView;
|
||||||
|
private ProductsRecyclerAdapter productsRecyclerAdapter;
|
||||||
|
|
||||||
|
private int buyerId = 1;
|
||||||
|
private String buyerName = "buyer1@test.com";
|
||||||
|
private String buyerPassword = "password";
|
||||||
|
private String buyerRole = "Buyer";
|
||||||
|
|
||||||
|
private int productId = 1;
|
||||||
|
private String productName = "TestProduct";
|
||||||
|
private int productPrice = 20000;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
scenario = ActivityScenario.launch(LoginActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
database = new Database(activity);
|
||||||
|
nama = activity.findViewById(R.id.textInputEditTextUsername);
|
||||||
|
password = activity.findViewById(R.id.textInputEditTextPassword);
|
||||||
|
loginButton = activity.findViewById(R.id.appCompatButtonLogin);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
scenario.close();
|
||||||
|
database.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Product addProduct(Database database) {
|
||||||
|
Product addedProduct = new Product();
|
||||||
|
addedProduct.setId(productId);
|
||||||
|
addedProduct.setName(productName);
|
||||||
|
addedProduct.setPrice(productPrice);
|
||||||
|
database.addProduct(addedProduct);
|
||||||
|
return addedProduct;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User buyerLogin(LoginActivity activity) {
|
||||||
|
User buyerUser = new User();
|
||||||
|
buyerUser.setId(buyerId);
|
||||||
|
buyerUser.setName(buyerName);
|
||||||
|
buyerUser.setPassword(buyerPassword);
|
||||||
|
buyerUser.setRole(buyerRole);
|
||||||
|
database.addUser(buyerUser);
|
||||||
|
|
||||||
|
nama.setText(buyerName);
|
||||||
|
password.setText(buyerPassword);
|
||||||
|
loginButton.performClick();
|
||||||
|
|
||||||
|
return buyerUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BuyerDetailProductActivity startBuyerDetailProductActivity(LoginActivity activity) {
|
||||||
|
product = addProduct(database);
|
||||||
|
user = buyerLogin(activity);
|
||||||
|
Intent intent = Shadows.shadowOf(activity).getNextStartedActivity();
|
||||||
|
|
||||||
|
BuyerHomeActivity buyerHomeActivity = Robolectric.buildActivity(BuyerHomeActivity.class, intent).create().start().get();
|
||||||
|
buyerHomeActivity.getDataFromSQLite();
|
||||||
|
|
||||||
|
RecyclerView recyclerView = (RecyclerView) buyerHomeActivity.findViewById(R.id.recyclerViewProducts);
|
||||||
|
ProductsRecyclerAdapter adapter = (ProductsRecyclerAdapter) recyclerView.getAdapter();
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
recyclerView.measure(0, 0);
|
||||||
|
recyclerView.layout(0, 0, 100, 10000);
|
||||||
|
|
||||||
|
View productView = recyclerView.getChildAt(0);
|
||||||
|
|
||||||
|
productView.performClick();
|
||||||
|
|
||||||
|
intent = Shadows.shadowOf(activity).getNextStartedActivity();
|
||||||
|
return Robolectric.buildActivity(BuyerDetailProductActivity.class, intent).create().start().get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddProducttoCart() {
|
||||||
|
scenario.onActivity(main -> {
|
||||||
|
BuyerDetailProductActivity activity = startBuyerDetailProductActivity(main);
|
||||||
|
TextInputEditText productQuantity = activity.findViewById(R.id.textInputEditTextProductQuantity);
|
||||||
|
AppCompatButton addButton = activity.findViewById(R.id.ButtonAddToCart);
|
||||||
|
|
||||||
|
productQuantity.setText("2");
|
||||||
|
addButton.performClick();
|
||||||
|
// assertTrue(database.checkCart(productId, productName, productPrice, buyerName));
|
||||||
|
testItem(true, database.checkCart(productId, productName, productPrice, buyerName), "Add Product to Cart function doesn't seem working, please check your add to cart button on click function inside BuyerDetailProductActivity or check your addCart function inside database class", 3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
215
TestC2MyShop011.java
Normal file
215
TestC2MyShop011.java
Normal file
|
|
@ -0,0 +1,215 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
import org.aplas.myshop.model.User;
|
||||||
|
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 java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestC2MyShop011 extends ViewTest {
|
||||||
|
ActivityScenario<LoginActivity> scenario;
|
||||||
|
private String packageName = "org.aplas";
|
||||||
|
private String targetDevice = "9";
|
||||||
|
private int minSDK = 21;
|
||||||
|
private String actName = "LoginActivity";
|
||||||
|
private String layoutName = "activity_login";
|
||||||
|
private String backwardComp = "AppCompatActivity";
|
||||||
|
//private String packName;
|
||||||
|
//ResourceTest rsc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initTest() {
|
||||||
|
scenario = ActivityScenario.launch(LoginActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_AppName() { //Check Project Name (Should be MyData)
|
||||||
|
//ActivityScenario<MainActivity> main = launchMainApp();
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Application Name is Wrong", appName.toLowerCase(), getAppName(activity.getPackageName()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_PackageName() { //Check Company Domain (Should be org.aplas.android)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
String packName = packageName+"."+appName.toLowerCase();
|
||||||
|
assertEquals("Package Name is Wrong", packName, activity.getPackageName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_03_TargetDevice() { //Check Target Device (Should be 6.0.1)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Target Device is Wrong",targetDevice, Build.VERSION.RELEASE);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_04_MinimumSDK() { //Check Minimum SDK (Should be 28)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Minimum SDK Version is Wrong",minSDK,activity.getApplicationInfo().minSdkVersion);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_05_ActivityName() { //Check Activity Name (Should be MyActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Activity Name is Wrong", actName, activity.getClass().getSimpleName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_06_LayoutName() { //Check Layout Name (Should be activity_layout)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
int resId = activity.getResources().getIdentifier(layoutName, "layout", activity.getPackageName());
|
||||||
|
assertNotEquals("Layout Name is Wrong", 0, resId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_07_ActivityParent() { //Check Backward Compatibility (Should be AppCompatActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Activity Parent is Wrong", backwardComp, activity.getClass().getSuperclass().getSimpleName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_08_String_Resource() {
|
||||||
|
//string check
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
org.aplas.myshop.ResourceTest rsc = new org.aplas.myshop.ResourceTest(activity.getResources());
|
||||||
|
rsc.testStringResource("app_name","MyShop");
|
||||||
|
rsc.testStringResource("hint_name","Name");
|
||||||
|
rsc.testStringResource("hint_username","Username");
|
||||||
|
rsc.testStringResource("hint_password","Password");
|
||||||
|
rsc.testStringResource("hint_confirm_password","Confirm Password");
|
||||||
|
rsc.testStringResource("text_login","Login");
|
||||||
|
rsc.testStringResource("text_register","Register");
|
||||||
|
rsc.testStringResource("error_message_username","Enter Username");
|
||||||
|
rsc.testStringResource("error_message_password","Enter Password");
|
||||||
|
rsc.testStringResource("error_message_role","Select Your Role");
|
||||||
|
rsc.testStringResource("success_message","Registration Successful");
|
||||||
|
rsc.testStringResource("text_not_member","No account yet? Create one");
|
||||||
|
rsc.testStringResource("text_already_member","Already a member? Login");
|
||||||
|
rsc.testStringResource("error_username_exists","Username Already Exists");
|
||||||
|
rsc.testStringResource("error_password_match","Password Does Not Matches");
|
||||||
|
rsc.testStringResource("error_valid_email_password","Wrong Email or Password");
|
||||||
|
rsc.testStringResource("radio_seller","Seller");
|
||||||
|
rsc.testStringResource("radio_buyer","Buyer");
|
||||||
|
rsc.testStringResource("hint_product_name","Product Name");
|
||||||
|
rsc.testStringResource("hint_product_price","Product Price");
|
||||||
|
rsc.testStringResource("hint_product_buyer","Product Buyer");
|
||||||
|
rsc.testStringResource("hint_product_quantity","Quantity");
|
||||||
|
rsc.testStringResource("text_add_product","Add Product");
|
||||||
|
rsc.testStringResource("text_remove_product","Remove Product");
|
||||||
|
rsc.testStringResource("text_add_to_cart","Add To Cart");
|
||||||
|
rsc.testStringResource("text_back","Back");
|
||||||
|
rsc.testStringResource("error_message_product_name","Enter Product Name");
|
||||||
|
rsc.testStringResource("error_message_product_price","Enter Product Price");
|
||||||
|
rsc.testStringResource("product_success_message","Add Product Successful");
|
||||||
|
rsc.testStringResource("error_product_exists","Product Already Exists");
|
||||||
|
String[] data = {"---You Want to Be A?---", "Seller", "Buyer"};
|
||||||
|
rsc.testStringArrayResource("roles",data);
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_09_Color_Resources() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
org.aplas.myshop.ResourceTest rsc = new org.aplas.myshop.ResourceTest(activity.getResources());
|
||||||
|
rsc.testColorResource(activity, "black", "#000000");
|
||||||
|
rsc.testColorResource(activity, "white", "#FFFFFF");
|
||||||
|
rsc.testColorResource(activity, "colorPrimary", "#51d8c7");
|
||||||
|
rsc.testColorResource(activity, "colorPrimaryDark", "#51d8c7");
|
||||||
|
rsc.testColorResource(activity, "colorAccent", "#FFFFFF");
|
||||||
|
rsc.testColorResource(activity, "colorBackground", "#001a33");
|
||||||
|
rsc.testColorResource(activity, "colorText", "#FFFFFF");
|
||||||
|
rsc.testColorResource(activity, "colorTextHint", "#51d8c7");
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_10_Image_Resource(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
org.aplas.myshop.ResourceTest rsc = new org.aplas.myshop.ResourceTest(activity.getResources());
|
||||||
|
rsc.testImgResource("myshop");
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_11_ImageView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("imgLogo","ImageView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_12_EditText(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("textInputEditTextUsername","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextPassword","EditText", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_13_Button(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("appCompatButtonLogin","Button", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_14_TextView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("textViewLinkRegister","TextView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_15_User_Class_Properties() {
|
||||||
|
String packname = "org.aplas.myshop.model";
|
||||||
|
String cname = "User";
|
||||||
|
try {
|
||||||
|
Class<?> c = Class.forName(packname+"."+cname);
|
||||||
|
Constructor<?> ctor = c.getConstructor();
|
||||||
|
Object obj = ctor.newInstance();
|
||||||
|
assertEquals("Class "+cname+" should be in 'model' directory", packname, obj.getClass().getPackage().getName());
|
||||||
|
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
||||||
|
failTest("Class " + cname + " is not defined ("+ e.toString() +")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getAppName(String packName) {
|
||||||
|
String[] list = packName.split("\\.");
|
||||||
|
String res = list[list.length-1];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
102
TestC2MyShop021.java
Normal file
102
TestC2MyShop021.java
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
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 java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestC2MyShop021 extends ViewTest {
|
||||||
|
ActivityScenario<RegisterActivity> scenario;
|
||||||
|
private String packageName = "org.aplas";
|
||||||
|
private String targetDevice = "9";
|
||||||
|
private int minSDK = 21;
|
||||||
|
private String actName = "RegisterActivity";
|
||||||
|
private String layoutName = "activity_register";
|
||||||
|
private String backwardComp = "AppCompatActivity";
|
||||||
|
//private String packName;
|
||||||
|
//ResourceTest rsc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initTest() {
|
||||||
|
scenario = ActivityScenario.launch(RegisterActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_ActivityName() { //Check Activity Name (Should be MyActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Activity Name is Wrong", actName, activity.getClass().getSimpleName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_LayoutName() { //Check Layout Name (Should be activity_layout)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
int resId = activity.getResources().getIdentifier(layoutName, "layout", activity.getPackageName());
|
||||||
|
assertNotEquals("Layout Name is Wrong", 0, resId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_03_ImageView() { //Check Backward Compatibility (Should be AppCompatActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("imgLogo","ImageView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_04_EditText(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("textInputEditTextName","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextPassword","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextConfirmPassword","EditText", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_05_Spinner(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
String spinner = "listRole";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_06_Button(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("appCompatButtonRegister","Button", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_07_TextView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("appCompatTextViewLoginLink","TextView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getAppName(String packName) {
|
||||||
|
String[] list = packName.split("\\.");
|
||||||
|
String res = list[list.length-1];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
107
TestC2MyShop031.java
Normal file
107
TestC2MyShop031.java
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
import org.aplas.myshop.adapters.ProductsRecyclerAdapter;
|
||||||
|
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 java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestC2MyShop031 extends ViewTest {
|
||||||
|
ActivityScenario<SellerHomeActivity> scenario;
|
||||||
|
private String packageName = "org.aplas";
|
||||||
|
private String targetDevice = "9";
|
||||||
|
private int minSDK = 21;
|
||||||
|
private String actName = "SellerHomeActivity";
|
||||||
|
private String layoutName = "activity_seller_home";
|
||||||
|
private String backwardComp = "AppCompatActivity";
|
||||||
|
//private String packName;
|
||||||
|
//ResourceTest rsc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initTest() {
|
||||||
|
scenario = ActivityScenario.launch(SellerHomeActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_ActivityName() { //Check Activity Name (Should be MyActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Activity Name is Wrong", actName, activity.getClass().getSimpleName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_LayoutName() { //Check Layout Name (Should be activity_layout)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
int resId = activity.getResources().getIdentifier(layoutName, "layout", activity.getPackageName());
|
||||||
|
assertNotEquals("Layout Name is Wrong", 0, resId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_03_TextView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("titleSellerHome","TextView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_04_RecyclerView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("recyclerViewProducts","RecyclerView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_05_Button(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("ButtonAddProduct","Button", activity);
|
||||||
|
testViewExist("ButtonRefreshProduct","Button", activity);
|
||||||
|
testViewExist("ButtonBuyerCart","Button", activity);
|
||||||
|
testViewExist("ButtonLogout","Button", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_06_Product_Class() {
|
||||||
|
String packname = "org.aplas.myshop.model";
|
||||||
|
String cname = "Product";
|
||||||
|
try {
|
||||||
|
Class<?> c = Class.forName(packname+"."+cname);
|
||||||
|
Constructor<?> ctor = c.getConstructor();
|
||||||
|
Object obj = ctor.newInstance();
|
||||||
|
assertEquals("Class "+cname+" should be in 'model' directory", packname, obj.getClass().getPackage().getName());
|
||||||
|
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
||||||
|
failTest("Class " + cname + " is not defined ("+ e.toString() +")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private String getAppName(String packName) {
|
||||||
|
String[] list = packName.split("\\.");
|
||||||
|
String res = list[list.length-1];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
86
TestC2MyShop041.java
Normal file
86
TestC2MyShop041.java
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
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 java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestC2MyShop041 extends ViewTest {
|
||||||
|
ActivityScenario<AddProductActivity> scenario;
|
||||||
|
private String packageName = "org.aplas";
|
||||||
|
private String targetDevice = "9";
|
||||||
|
private int minSDK = 21;
|
||||||
|
private String actName = "AddProductActivity";
|
||||||
|
private String layoutName = "activity_add_product";
|
||||||
|
private String backwardComp = "AppCompatActivity";
|
||||||
|
//private String packName;
|
||||||
|
//ResourceTest rsc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initTest() {
|
||||||
|
scenario = ActivityScenario.launch(AddProductActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_ActivityName() { //Check Activity Name (Should be MyActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Activity Name is Wrong", actName, activity.getClass().getSimpleName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_LayoutName() { //Check Layout Name (Should be activity_layout)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
int resId = activity.getResources().getIdentifier(layoutName, "layout", activity.getPackageName());
|
||||||
|
assertNotEquals("Layout Name is Wrong", 0, resId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_03_TextView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("titleAddProduct","TextView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_04_EditText (){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("textInputEditTextProductName","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextProductPrice","EditText", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_05_Button(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("appCompatButtonAddProduct","Button", activity);
|
||||||
|
testViewExist("appCompatButtonCancelAddProduct","Button", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getAppName(String packName) {
|
||||||
|
String[] list = packName.split("\\.");
|
||||||
|
String res = list[list.length-1];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
83
TestC2MyShop051.java
Normal file
83
TestC2MyShop051.java
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
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 static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestC2MyShop051 extends ViewTest {
|
||||||
|
ActivityScenario<SellerDetailProductActivity> scenario;
|
||||||
|
private String packageName = "org.aplas";
|
||||||
|
private String targetDevice = "9";
|
||||||
|
private int minSDK = 21;
|
||||||
|
private String actName = "SellerDetailProductActivity";
|
||||||
|
private String layoutName = "activity_seller_detail_product";
|
||||||
|
private String backwardComp = "AppCompatActivity";
|
||||||
|
//private String packName;
|
||||||
|
//ResourceTest rsc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initTest() {
|
||||||
|
scenario = ActivityScenario.launch(SellerDetailProductActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_ActivityName() { //Check Activity Name (Should be MyActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Activity Name is Wrong", actName, activity.getClass().getSimpleName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_LayoutName() { //Check Layout Name (Should be activity_layout)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
int resId = activity.getResources().getIdentifier(layoutName, "layout", activity.getPackageName());
|
||||||
|
assertNotEquals("Layout Name is Wrong", 0, resId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_03_TextView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("titleProductDetailSeller","TextView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_04_EditText (){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("textInputEditTextProductName","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextProductPrice","EditText", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_05_Button(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("ButtonRemoveProduct","Button", activity);
|
||||||
|
testViewExist("ButtonBack","Button", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getAppName(String packName) {
|
||||||
|
String[] list = packName.split("\\.");
|
||||||
|
String res = list[list.length-1];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
82
TestC2MyShop061.java
Normal file
82
TestC2MyShop061.java
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
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 static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestC2MyShop061 extends ViewTest {
|
||||||
|
ActivityScenario<BuyerHomeActivity> scenario;
|
||||||
|
private String packageName = "org.aplas";
|
||||||
|
private String targetDevice = "9";
|
||||||
|
private int minSDK = 21;
|
||||||
|
private String actName = "BuyerHomeActivity";
|
||||||
|
private String layoutName = "activity_buyer_home";
|
||||||
|
private String backwardComp = "AppCompatActivity";
|
||||||
|
//private String packName;
|
||||||
|
//ResourceTest rsc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initTest() {
|
||||||
|
scenario = ActivityScenario.launch(BuyerHomeActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_ActivityName() { //Check Activity Name (Should be MyActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Activity Name is Wrong", actName, activity.getClass().getSimpleName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_LayoutName() { //Check Layout Name (Should be activity_layout)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
int resId = activity.getResources().getIdentifier(layoutName, "layout", activity.getPackageName());
|
||||||
|
assertNotEquals("Layout Name is Wrong", 0, resId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_03_TextView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("titleBuyerHome","TextView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_04_RecyclerView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("recyclerViewProducts","RecyclerView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_05_Button(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("ButtonBuyerCart","Button", activity);
|
||||||
|
testViewExist("ButtonLogout","Button", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getAppName(String packName) {
|
||||||
|
String[] list = packName.split("\\.");
|
||||||
|
String res = list[list.length-1];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
84
TestC2MyShop071.java
Normal file
84
TestC2MyShop071.java
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
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 static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestC2MyShop071 extends ViewTest {
|
||||||
|
ActivityScenario<BuyerDetailProductActivity> scenario;
|
||||||
|
private String packageName = "org.aplas";
|
||||||
|
private String targetDevice = "9";
|
||||||
|
private int minSDK = 21;
|
||||||
|
private String actName = "BuyerDetailProductActivity";
|
||||||
|
private String layoutName = "activity_buyer_detail_product";
|
||||||
|
private String backwardComp = "AppCompatActivity";
|
||||||
|
//private String packName;
|
||||||
|
//ResourceTest rsc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initTest() {
|
||||||
|
scenario = ActivityScenario.launch(BuyerDetailProductActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_ActivityName() { //Check Activity Name (Should be MyActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Activity Name is Wrong", actName, activity.getClass().getSimpleName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_LayoutName() { //Check Layout Name (Should be activity_layout)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
int resId = activity.getResources().getIdentifier(layoutName, "layout", activity.getPackageName());
|
||||||
|
assertNotEquals("Layout Name is Wrong", 0, resId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_03_TextView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("titleProductDetailBuyer","TextView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_04_EditText (){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("textInputEditTextProductName","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextProductPrice","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextProductQuantity","EditText", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_05_Button(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("ButtonAddToCart","Button", activity);
|
||||||
|
testViewExist("ButtonBack","Button", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getAppName(String packName) {
|
||||||
|
String[] list = packName.split("\\.");
|
||||||
|
String res = list[list.length-1];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
82
TestC2MyShop081.java
Normal file
82
TestC2MyShop081.java
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
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 static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestC2MyShop081 extends ViewTest {
|
||||||
|
ActivityScenario<BuyerCartActivity> scenario;
|
||||||
|
private String packageName = "org.aplas";
|
||||||
|
private String targetDevice = "9";
|
||||||
|
private int minSDK = 21;
|
||||||
|
private String actName = "BuyerCartActivity";
|
||||||
|
private String layoutName = "activity_buyer_cart";
|
||||||
|
private String backwardComp = "AppCompatActivity";
|
||||||
|
//private String packName;
|
||||||
|
//ResourceTest rsc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initTest() {
|
||||||
|
scenario = ActivityScenario.launch(BuyerCartActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_ActivityName() { //Check Activity Name (Should be MyActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Activity Name is Wrong", actName, activity.getClass().getSimpleName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_LayoutName() { //Check Layout Name (Should be activity_layout)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
int resId = activity.getResources().getIdentifier(layoutName, "layout", activity.getPackageName());
|
||||||
|
assertNotEquals("Layout Name is Wrong", 0, resId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_03_TextView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("titleCartBuyer","TextView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_04_RecyclerView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("recyclerViewCarts","RecyclerView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_05_Button(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("ButtonRefreshCart","Button", activity);
|
||||||
|
testViewExist("ButtonBack","Button", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getAppName(String packName) {
|
||||||
|
String[] list = packName.split("\\.");
|
||||||
|
String res = list[list.length-1];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
85
TestC2MyShop091.java
Normal file
85
TestC2MyShop091.java
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
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 static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestC2MyShop091 extends ViewTest {
|
||||||
|
ActivityScenario<BuyerDetailCartActivity> scenario;
|
||||||
|
private String packageName = "org.aplas";
|
||||||
|
private String targetDevice = "9";
|
||||||
|
private int minSDK = 21;
|
||||||
|
private String actName = "BuyerDetailCartActivity";
|
||||||
|
private String layoutName = "activity_buyer_detail_cart";
|
||||||
|
private String backwardComp = "AppCompatActivity";
|
||||||
|
//private String packName;
|
||||||
|
//ResourceTest rsc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initTest() {
|
||||||
|
scenario = ActivityScenario.launch(BuyerDetailCartActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_ActivityName() { //Check Activity Name (Should be MyActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Activity Name is Wrong", actName, activity.getClass().getSimpleName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_LayoutName() { //Check Layout Name (Should be activity_layout)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
int resId = activity.getResources().getIdentifier(layoutName, "layout", activity.getPackageName());
|
||||||
|
assertNotEquals("Layout Name is Wrong", 0, resId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_03_TextView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("titleDetailCartProductBuyer","TextView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_04_EditText(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("textInputEditTextProductName","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextProductPrice","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextProductQuantity","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextProductBuyer","EditText", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_05_Button(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("ButtonDeleteFromCart","Button", activity);
|
||||||
|
testViewExist("ButtonBack","Button", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getAppName(String packName) {
|
||||||
|
String[] list = packName.split("\\.");
|
||||||
|
String res = list[list.length-1];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
82
TestC2MyShop101.java
Normal file
82
TestC2MyShop101.java
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
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 static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestC2MyShop101 extends ViewTest {
|
||||||
|
ActivityScenario<SellerCartActivity> scenario;
|
||||||
|
private String packageName = "org.aplas";
|
||||||
|
private String targetDevice = "9";
|
||||||
|
private int minSDK = 21;
|
||||||
|
private String actName = "SellerCartActivity";
|
||||||
|
private String layoutName = "activity_seller_cart";
|
||||||
|
private String backwardComp = "AppCompatActivity";
|
||||||
|
//private String packName;
|
||||||
|
//ResourceTest rsc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initTest() {
|
||||||
|
scenario = ActivityScenario.launch(SellerCartActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_ActivityName() { //Check Activity Name (Should be MyActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Activity Name is Wrong", actName, activity.getClass().getSimpleName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_LayoutName() { //Check Layout Name (Should be activity_layout)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
int resId = activity.getResources().getIdentifier(layoutName, "layout", activity.getPackageName());
|
||||||
|
assertNotEquals("Layout Name is Wrong", 0, resId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_03_TextView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("titleCartSeller","TextView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_04_RecyclerView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("recyclerViewCarts","RecyclerView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_05_Button(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("ButtonRefreshCart","Button", activity);
|
||||||
|
testViewExist("ButtonBack","Button", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getAppName(String packName) {
|
||||||
|
String[] list = packName.split("\\.");
|
||||||
|
String res = list[list.length-1];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
85
TestC2MyShop111.java
Normal file
85
TestC2MyShop111.java
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
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 static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestC2MyShop111 extends ViewTest {
|
||||||
|
ActivityScenario<SellerDetailCartActivity> scenario;
|
||||||
|
private String packageName = "org.aplas";
|
||||||
|
private String targetDevice = "9";
|
||||||
|
private int minSDK = 21;
|
||||||
|
private String actName = "SellerDetailCartActivity";
|
||||||
|
private String layoutName = "activity_seller_detail_cart";
|
||||||
|
private String backwardComp = "AppCompatActivity";
|
||||||
|
//private String packName;
|
||||||
|
//ResourceTest rsc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initTest() {
|
||||||
|
scenario = ActivityScenario.launch(SellerDetailCartActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_ActivityName() { //Check Activity Name (Should be MyActivity)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
assertEquals("Activity Name is Wrong", actName, activity.getClass().getSimpleName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_LayoutName() { //Check Layout Name (Should be activity_layout)
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
int resId = activity.getResources().getIdentifier(layoutName, "layout", activity.getPackageName());
|
||||||
|
assertNotEquals("Layout Name is Wrong", 0, resId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_03_TextView(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("titleDetailCartSeller","TextView", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_04_EditText(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("textInputEditTextProductName","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextProductPrice","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextProductQuantity","EditText", activity);
|
||||||
|
testViewExist("textInputEditTextProductBuyer","EditText", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_05_Button(){
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
testViewExist("ButtonDeleteFromCart","Button", activity);
|
||||||
|
testViewExist("ButtonBack","Button", activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getAppName(String packName) {
|
||||||
|
String[] list = packName.split("\\.");
|
||||||
|
String res = list[list.length-1];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
96
TestDeleteCart.java
Normal file
96
TestDeleteCart.java
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.appcompat.widget.AppCompatButton;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
import org.aplas.myshop.adapters.CartsRecyclerAdapter;
|
||||||
|
import org.aplas.myshop.model.Cart;
|
||||||
|
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.Robolectric;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.Shadows;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class TestDeleteCart extends ViewTest{
|
||||||
|
ActivityScenario<SellerCartActivity> scenario;
|
||||||
|
private Database database;
|
||||||
|
|
||||||
|
private int cartId = 1;
|
||||||
|
private String cartUsername = "buyercart@test.com";
|
||||||
|
private int productId = 1;
|
||||||
|
private String productName = "CartProductTest";
|
||||||
|
private int productPrice = 25000;
|
||||||
|
private int productQuantity = 3;
|
||||||
|
private Cart cart;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
scenario = ActivityScenario.launch(SellerCartActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
database = new Database(activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
scenario.close();
|
||||||
|
database.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cart addCart(Database database) {
|
||||||
|
Cart addedCart = new Cart();
|
||||||
|
addedCart.setId(cartId);
|
||||||
|
addedCart.setUsername(cartUsername);
|
||||||
|
addedCart.setProductId(productId);
|
||||||
|
addedCart.setProductName(productName);
|
||||||
|
addedCart.setProductPrice(productPrice);
|
||||||
|
addedCart.setProductQuantity(productQuantity);
|
||||||
|
database.addCart(addedCart);
|
||||||
|
return addedCart;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SellerDetailCartActivity startSellerDetailCartActivity(SellerCartActivity activity) {
|
||||||
|
cart = addCart(database);
|
||||||
|
activity.getDataFromSQLite();
|
||||||
|
RecyclerView recyclerView = activity.findViewById(R.id.recyclerViewCarts);
|
||||||
|
CartsRecyclerAdapter adapter = (CartsRecyclerAdapter) recyclerView.getAdapter();
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
recyclerView.measure(0, 0);
|
||||||
|
recyclerView.layout(0, 0, 100, 10000);
|
||||||
|
|
||||||
|
View cartView = recyclerView.getChildAt(0);
|
||||||
|
cartView.performClick();
|
||||||
|
Intent intent = Shadows.shadowOf(activity).getNextStartedActivity();
|
||||||
|
return Robolectric.buildActivity(SellerDetailCartActivity.class, intent).create().start().get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteCart() {
|
||||||
|
scenario.onActivity(main -> {
|
||||||
|
SellerDetailCartActivity activity = startSellerDetailCartActivity(main);
|
||||||
|
AppCompatButton deleteButton = activity.findViewById(R.id.ButtonDeleteFromCart);
|
||||||
|
deleteButton.performClick();
|
||||||
|
|
||||||
|
// assertFalse(database.checkCart(productId, productName, productPrice, cartUsername));
|
||||||
|
testItem(false, database.checkCart(productId, productName, productPrice, cartUsername), "Delete cart function doesn't seem working, please check your delete cart button on click function inside SellerDetailCartActivity or check your delete cart function inside the database class", 4);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
94
TestDeleteProduct.java
Normal file
94
TestDeleteProduct.java
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.appcompat.widget.AppCompatButton;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
import org.aplas.myshop.adapters.ProductsRecyclerAdapter;
|
||||||
|
import org.aplas.myshop.model.Product;
|
||||||
|
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.Robolectric;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.Shadows;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class TestDeleteProduct extends ViewTest{
|
||||||
|
ActivityScenario<SellerHomeActivity> scenario;
|
||||||
|
private Database database;
|
||||||
|
private Product product;
|
||||||
|
private RecyclerView recyclerView;
|
||||||
|
private ProductsRecyclerAdapter productsRecyclerAdapter;
|
||||||
|
private int productId = 1;
|
||||||
|
private String productName = "TestProduct";
|
||||||
|
private int productPrice = 20000;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
scenario = ActivityScenario.launch(SellerHomeActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
database = new Database(activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
scenario.close();
|
||||||
|
database.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Product addProduct(Database database) {
|
||||||
|
Product addedProduct = new Product();
|
||||||
|
addedProduct.setId(productId);
|
||||||
|
addedProduct.setName(productName);
|
||||||
|
addedProduct.setPrice(productPrice);
|
||||||
|
database.addProduct(addedProduct);
|
||||||
|
return addedProduct;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SellerDetailProductActivity startSellerDetailProductActivity(SellerHomeActivity activity) {
|
||||||
|
product = addProduct(database);
|
||||||
|
activity.getDataFromSQLite();
|
||||||
|
|
||||||
|
RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recyclerViewProducts);
|
||||||
|
ProductsRecyclerAdapter adapter = (ProductsRecyclerAdapter) recyclerView.getAdapter();
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
recyclerView.measure(0, 0);
|
||||||
|
recyclerView.layout(0, 0, 100, 10000);
|
||||||
|
|
||||||
|
View productView = recyclerView.getChildAt(0);
|
||||||
|
|
||||||
|
productView.performClick();
|
||||||
|
|
||||||
|
Intent intent = Shadows.shadowOf(activity).getNextStartedActivity();
|
||||||
|
return Robolectric.buildActivity(SellerDetailProductActivity.class, intent).create().start().get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteProduct() {
|
||||||
|
scenario.onActivity(main -> {
|
||||||
|
SellerDetailProductActivity activity = startSellerDetailProductActivity(main);
|
||||||
|
AppCompatButton removeButton = (AppCompatButton) activity.findViewById(R.id.ButtonRemoveProduct);
|
||||||
|
removeButton.performClick();
|
||||||
|
// assertFalse(database.checkProduct(productName, String.valueOf(productPrice)));
|
||||||
|
testItem(false, database.checkProduct(productName, String.valueOf(productPrice)), "Delete product function doesn't seem working, please check your delete button on click function inside SellerDetailProductActivity or check your delete product function inside the database class", 4);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
TestFiles.rar
BIN
TestFiles.rar
Binary file not shown.
73
TestLoginFail.java
Normal file
73
TestLoginFail.java
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
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.TextInputLayout;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
public class TestLoginFail extends ViewTest{
|
||||||
|
ActivityScenario<LoginActivity> scenario;
|
||||||
|
private EditText nama, password;
|
||||||
|
private TextInputLayout namaLayout, passwordLayout;
|
||||||
|
private Button loginButton;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
scenario = ActivityScenario.launch(LoginActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama = activity.findViewById(R.id.textInputEditTextUsername);
|
||||||
|
namaLayout = activity.findViewById(R.id.textInputLayoutUsername);
|
||||||
|
password = activity.findViewById(R.id.textInputEditTextPassword);
|
||||||
|
passwordLayout = activity.findViewById(R.id.textInputLayoutPassword);
|
||||||
|
loginButton = activity.findViewById(R.id.appCompatButtonLogin);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
scenario.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_EmptyName() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama.setText("");
|
||||||
|
password.setText("password");
|
||||||
|
loginButton.performClick();
|
||||||
|
String expectedErrorMessage = "Enter Username";
|
||||||
|
assertNotNull("The text layout should throw error when username is empty, please check your input validation inside LoginActivity and make sure it has the same message according to guide file", namaLayout.getError());
|
||||||
|
String actualErrorMessage = namaLayout.getError().toString();
|
||||||
|
testItem(expectedErrorMessage, actualErrorMessage, "Error message does not match, please check your input validation inside LoginActivity and make sure it has the same message according to guide file", 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_EmptyPassword() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama.setText("test@example.com");
|
||||||
|
password.setText("");
|
||||||
|
loginButton.performClick();
|
||||||
|
String expectedErrorMessage = "Enter Password";
|
||||||
|
assertNotNull("The text layout should throw error when password is empty, please check your input validation inside LoginActivity and make sure it has the same message according to guide file", passwordLayout.getError());
|
||||||
|
String actualErrorMessage = passwordLayout.getError().toString();
|
||||||
|
testItem(expectedErrorMessage, actualErrorMessage, "Error message does not match, please check your input validation inside LoginActivity and make sure it has the same message according to guide file", 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
119
TestLoginSuccess.java
Normal file
119
TestLoginSuccess.java
Normal file
|
|
@ -0,0 +1,119 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
import org.aplas.myshop.model.User;
|
||||||
|
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 static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
|
|
||||||
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestLoginSuccess extends ViewTest{
|
||||||
|
ActivityScenario<LoginActivity> scenario;
|
||||||
|
private EditText nama, password;
|
||||||
|
private Database database;
|
||||||
|
private Button loginButton;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
scenario = ActivityScenario.launch(LoginActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama = activity.findViewById(R.id.textInputEditTextUsername);
|
||||||
|
password = activity.findViewById(R.id.textInputEditTextPassword);
|
||||||
|
loginButton = activity.findViewById(R.id.appCompatButtonLogin);
|
||||||
|
database = new Database(activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
scenario.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test01Seller() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
User user = new User();
|
||||||
|
user.setName("daffa1@test.com");
|
||||||
|
user.setPassword("password");
|
||||||
|
user.setRole("Seller");
|
||||||
|
database.addUser(user);
|
||||||
|
|
||||||
|
nama.setText("daffa1@test.com");
|
||||||
|
password.setText("password");
|
||||||
|
loginButton.performClick();
|
||||||
|
Intent expectedIntent = new Intent(activity, SellerHomeActivity.class);
|
||||||
|
expectedIntent.putExtra("Username", "daffa1@test.com");
|
||||||
|
Intent actualIntent = shadowOf(activity).getNextStartedActivity();
|
||||||
|
assertNotNull("No intents detected, please check your login button on click function inside LoginActivity", actualIntent);
|
||||||
|
testItem(expectedIntent.getComponent(), actualIntent.getComponent(), "Intents do not match, please check your login button on click function inside LoginActivity", 1);
|
||||||
|
database.close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test02Buyer() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
User user = new User();
|
||||||
|
user.setName("daffa2@test.com");
|
||||||
|
user.setPassword("password");
|
||||||
|
user.setRole("Buyer");
|
||||||
|
database.addUser(user);
|
||||||
|
|
||||||
|
nama.setText("daffa2@test.com");
|
||||||
|
password.setText("password");
|
||||||
|
loginButton.performClick();
|
||||||
|
Intent expectedIntent = new Intent(activity, BuyerHomeActivity.class);
|
||||||
|
expectedIntent.putExtra("Username", "daffa2@test.com");
|
||||||
|
Intent actualIntent = shadowOf(activity).getNextStartedActivity();
|
||||||
|
assertNotNull("No intents detected, please check your login button on click function inside LoginActivity", actualIntent);
|
||||||
|
testItem(expectedIntent.getComponent(), actualIntent.getComponent(), "Intents do not match, please check your login button on click function inside LoginActivity", 1);
|
||||||
|
database.close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test03invalid() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
Database database = mock(Database.class);
|
||||||
|
activity.setDatabase(database);
|
||||||
|
|
||||||
|
nama.setText("daffa3@test.com");
|
||||||
|
password.setText("password");
|
||||||
|
|
||||||
|
when(database.checkUser("daffa3@test.com", "password")).thenReturn(false);
|
||||||
|
|
||||||
|
loginButton.performClick();
|
||||||
|
Snackbar snackbar = Snackbar.make(activity.findViewById(R.id.nestedScrollViewProduct),activity.getString(R.string.error_valid_email_password), Snackbar.LENGTH_LONG);
|
||||||
|
snackbar.show();
|
||||||
|
// assertTrue(snackbar.isShown());
|
||||||
|
testItem(true, snackbar.isShown(), "Your login function doesn't seem working, please check your login button on click function inside LoginActivity", 3);
|
||||||
|
database.close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
93
TestRegisterFail.java
Normal file
93
TestRegisterFail.java
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import androidx.appcompat.widget.AppCompatButton;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ActivityScenario;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest= Config.NONE)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
|
||||||
|
public class TestRegisterFail extends ViewTest{
|
||||||
|
ActivityScenario<RegisterActivity> scenario;
|
||||||
|
|
||||||
|
private TextInputEditText nama, password, confirmPassword;
|
||||||
|
private TextInputLayout namaLayout, passwordLayout, confPasswordLayout;
|
||||||
|
private AppCompatButton registerButton;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
scenario = ActivityScenario.launch(RegisterActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama = activity.findViewById(R.id.textInputEditTextName);
|
||||||
|
password = activity.findViewById(R.id.textInputEditTextPassword);
|
||||||
|
confirmPassword = activity.findViewById(R.id.textInputEditTextConfirmPassword);
|
||||||
|
namaLayout = activity.findViewById(R.id.textInputLayoutName);
|
||||||
|
passwordLayout = activity.findViewById(R.id.textInputLayoutPassword);
|
||||||
|
confPasswordLayout = activity.findViewById(R.id.textInputLayoutConfirmPassword);
|
||||||
|
registerButton = activity.findViewById(R.id.appCompatButtonRegister);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
scenario.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_EmptyName() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama.setText("");
|
||||||
|
password.setText("password");
|
||||||
|
confirmPassword.setText("password");
|
||||||
|
registerButton.performClick();
|
||||||
|
String expectedErrorMessage = "Enter Username";
|
||||||
|
assertNotNull("The text layout should throw error when username is empty during registration, please check your name input validation in RegisterActivity and make sure it has the same error message according to guide file.", namaLayout.getError());
|
||||||
|
String actualErrorMessage = namaLayout.getError().toString();
|
||||||
|
testItem(expectedErrorMessage, actualErrorMessage, "Error message does not match, please check your name input validation in RegisterActivity and make sure it has the same error message according to guide file.", 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_EmptyPassword() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama.setText("test@example.com");
|
||||||
|
password.setText("");
|
||||||
|
confirmPassword.setText("password");
|
||||||
|
registerButton.performClick();
|
||||||
|
String expectedErrorMessage = "Enter Password";
|
||||||
|
assertNotNull("The text layout should throw error when password is empty during registration, please check your name input validation in RegisterActivity and make sure it has the same error message according to guide file.", passwordLayout.getError());
|
||||||
|
String actualErrorMessage = passwordLayout.getError().toString();
|
||||||
|
testItem(expectedErrorMessage, actualErrorMessage, "Error message does not match, please check your password input validation in RegisterActivity and make sure it has the same error message according to guide file.", 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_03_PasswordNotMatch() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama.setText("test@example.com");
|
||||||
|
password.setText("password");
|
||||||
|
confirmPassword.setText("differentpassword");
|
||||||
|
registerButton.performClick();
|
||||||
|
String expectedErrorMessage = "Password Does Not Matches";
|
||||||
|
assertNotNull("The text layout should throw error when confirm password does not match during registration, please check your confirm password input validation in RegisterActivity and make sure it has the same error message according to guide file.", confPasswordLayout.getError());
|
||||||
|
String actualErrorMessage = confPasswordLayout.getError().toString();
|
||||||
|
testItem(expectedErrorMessage, actualErrorMessage, "Error message does not match, please check your confirm password input validation in RegisterActivity and make sure it has the same error message according to guide file.", 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
78
TestRegisterSuccess.java
Normal file
78
TestRegisterSuccess.java
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import android.widget.Spinner;
|
||||||
|
|
||||||
|
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 TestRegisterSuccess extends ViewTest{
|
||||||
|
ActivityScenario<RegisterActivity> scenario;
|
||||||
|
|
||||||
|
private TextInputEditText nama, password, confirmPassword;
|
||||||
|
private AppCompatButton registerButton;
|
||||||
|
private Spinner spinnerRoles;
|
||||||
|
private Database database;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
scenario = ActivityScenario.launch(RegisterActivity.class);
|
||||||
|
scenario.moveToState(Lifecycle.State.CREATED);
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama = activity.findViewById(R.id.textInputEditTextName);
|
||||||
|
password = activity.findViewById(R.id.textInputEditTextPassword);
|
||||||
|
confirmPassword = activity.findViewById(R.id.textInputEditTextConfirmPassword);
|
||||||
|
registerButton = activity.findViewById(R.id.appCompatButtonRegister);
|
||||||
|
spinnerRoles = activity.findViewById(R.id.listRoles);
|
||||||
|
database = new Database(activity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
scenario.close();
|
||||||
|
database.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_01_Seller() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama.setText("seller1@test.com");
|
||||||
|
password.setText("password");
|
||||||
|
confirmPassword.setText("password");
|
||||||
|
spinnerRoles.setSelection(1);
|
||||||
|
registerButton.performClick();
|
||||||
|
// assertTrue(database.checkUser("seller1@test.com"));
|
||||||
|
testItem(true, database.checkUser("seller1@test.com"), "Your register function doesn't seem to work, please check your register button on click function inside RegisterActivity or check Add User function inside the Database class", 3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void check_02_Buyer() {
|
||||||
|
scenario.onActivity(activity -> {
|
||||||
|
nama.setText("buyer1@test.com");
|
||||||
|
password.setText("password");
|
||||||
|
confirmPassword.setText("password");
|
||||||
|
spinnerRoles.setSelection(2);
|
||||||
|
registerButton.performClick();
|
||||||
|
// assertTrue(database.checkUser("buyer1@test.com"));
|
||||||
|
testItem(true, database.checkUser("seller1@test.com"), "Your register function doesn't seem to work, please check your register button on click function inside RegisterActivity or check Add User function inside the Database class", 3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
570
ViewTest.java
Normal file
570
ViewTest.java
Normal file
|
|
@ -0,0 +1,570 @@
|
||||||
|
package org.aplas.myshop;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.ColorStateList;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.graphics.drawable.RippleDrawable;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.robolectric.Shadows;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
public class ViewTest {
|
||||||
|
final String UNDECLARED_CODE = "APLAS-UNDECLARED";
|
||||||
|
public static final String appName = "MyShop";
|
||||||
|
|
||||||
|
protected View getViewFromActivity(String name, Activity activity) {
|
||||||
|
int id = activity.getResources().getIdentifier(name, "id", activity.getPackageName());
|
||||||
|
return (id > 0)?(View) activity.findViewById(id):null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected View getViewFromFragment(String name, Fragment fragment) {
|
||||||
|
int id = fragment.getResources().getIdentifier(name, "id", fragment.getActivity().getPackageName());
|
||||||
|
return (id > 0)?(View) fragment.getView().findViewById(id):null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getViewName(View view) {
|
||||||
|
return (view.getId()<0)?"":view.getResources().getResourceEntryName(view.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getRscId(String name, String type, Activity activity) {
|
||||||
|
return activity.getResources().getIdentifier(name, type, activity.getPackageName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private View currView;
|
||||||
|
private boolean found;
|
||||||
|
|
||||||
|
protected void findViewFromLayout(String name, View view) {
|
||||||
|
String viewName = getViewName(view);
|
||||||
|
if (viewName.equals(name)) {
|
||||||
|
currView=view;
|
||||||
|
found=true;
|
||||||
|
} else {
|
||||||
|
if (view instanceof ViewGroup) {
|
||||||
|
int i=0;
|
||||||
|
int childCount = ((ViewGroup) view).getChildCount();
|
||||||
|
while (i<childCount && !found) {
|
||||||
|
findViewFromLayout(name,((ViewGroup) view).getChildAt(i));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected View getViLayout(String name, View view) {
|
||||||
|
currView=null;
|
||||||
|
found=false;
|
||||||
|
//findViewFromLayout(name,view);
|
||||||
|
return currView;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected View getLayoutFromResource(String rscName, Activity activity, String layoutType) {
|
||||||
|
int rscId = getRscId(rscName,"layout",activity);
|
||||||
|
Assert.assertNotEquals(rscName+".xml is not exist!!",0,rscId);
|
||||||
|
LayoutInflater li = LayoutInflater.from(activity.getApplicationContext());
|
||||||
|
View view = li.inflate(rscId, null);
|
||||||
|
Assert.assertEquals(rscName+".xml should be a "+layoutType,view.getClass().getSimpleName(),layoutType);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected View getViewFromLayout(String name, View layout) {
|
||||||
|
//layout.getContext()
|
||||||
|
int id = layout.getContext().getResources().getIdentifier(name, "id", layout.getContext().getPackageName());
|
||||||
|
return (id > 0)?(View) layout.findViewById(id):null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected View getViewFromDialog(String name, Dialog layout) {
|
||||||
|
//layout.getContext()
|
||||||
|
int id = layout.getContext().getResources().getIdentifier(name, "id", layout.getContext().getPackageName());
|
||||||
|
return (id > 0)?(View) layout.findViewById(id):null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void testClassExist(String cname) {
|
||||||
|
try {
|
||||||
|
Class.forName(cname);
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail(cname+" is not exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String testViewContent(View view, String expClass, String expText) {
|
||||||
|
String viewName = testViewExist(view,expClass);
|
||||||
|
assertEquals("Text of "+expClass+" '"+viewName+"' is wrong",expText,((TextView)view).getText().toString());
|
||||||
|
return viewName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void testViewContent(View view, String expClass, String expText, String expHint) {
|
||||||
|
String viewName = testViewContent(view,expClass,expText);
|
||||||
|
assertEquals("Hint of "+viewName+" is wrong",expHint,((TextView)view).getHint().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void testViewContent(View view, String expClass, String expText, boolean expEnabled) {
|
||||||
|
String viewName = testViewContent(view,expClass,expText);
|
||||||
|
assertEquals("Enabled status "+viewName+" is wrong",expEnabled,view.isEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String testViewContent(View view, String expText) {
|
||||||
|
String viewName = getViewName(view);
|
||||||
|
assertEquals("Text of '"+viewName+"' is wrong",expText,((TextView)view).getText().toString());
|
||||||
|
return viewName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String testViewContains(View view, String expText) {
|
||||||
|
String viewName = getViewName(view);
|
||||||
|
testItem(0,((TextView)view).getText().toString().contains(expText),
|
||||||
|
"Text of '"+viewName+"' should contain "+expText,3);
|
||||||
|
return viewName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void testViewEnabled(View view, boolean expEnabled) {
|
||||||
|
String viewName = getViewName(view);
|
||||||
|
assertEquals("Enabled status "+viewName+" is wrong",expEnabled,view.isEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String testViewExist(View view, String expClass) {
|
||||||
|
assertNotNull(expClass+" is not found",view);
|
||||||
|
String viewName = getViewName(view);
|
||||||
|
assertEquals("View with id="+viewName+" should be a "+expClass, expClass, view.getClass().getSimpleName());
|
||||||
|
return viewName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected View testViewExist(String name, String expClass, Activity activity) {
|
||||||
|
int id = activity.getResources().getIdentifier(name, "id", activity.getPackageName());
|
||||||
|
if (id>0) {
|
||||||
|
View view = activity.findViewById(id);
|
||||||
|
String actClass = view.getClass().getSimpleName();
|
||||||
|
testItem(0,actClass.contains(expClass),
|
||||||
|
"View with id="+name+" should be a "+expClass+", not "+actClass, 3);
|
||||||
|
return view;
|
||||||
|
} else {
|
||||||
|
fail("View with id='"+name+"' is not found in "+activity.getClass().getSimpleName());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected View testViewExist(String name, String expClass, View layout) {
|
||||||
|
int id = layout.getResources().getIdentifier(name, "id", layout.getContext().getPackageName());
|
||||||
|
if (id>0) {
|
||||||
|
View view = layout.findViewById(id);
|
||||||
|
String actClass = view.getClass().getSimpleName();
|
||||||
|
testItem(0,actClass.contains(expClass),
|
||||||
|
"View with id="+name+" should be a "+expClass+", not "+actClass, 3);
|
||||||
|
return view;
|
||||||
|
} else {
|
||||||
|
fail("View with id='"+name+"' is not found in "+layout.getClass().getSimpleName());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Object testFieldExist(String name, String expClass, Activity activity) {
|
||||||
|
Object field = getFieldValue(activity,name);
|
||||||
|
if (field.getClass().getSimpleName().equals("String")) {
|
||||||
|
if (((String) field).equals(UNDECLARED_CODE)) {
|
||||||
|
assertNotNull("Field " + name + " is not yet declared!!", field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals("Field '"+name+"' should be a "+expClass, expClass, field.getClass().getSimpleName());
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected View testFieldViewExist(String name, String expClass, Activity activity) {
|
||||||
|
Object field = getFieldValue(activity,name);
|
||||||
|
if (field.getClass().getSimpleName().equals("String")) {
|
||||||
|
if (((String) field).equals(UNDECLARED_CODE)) {
|
||||||
|
assertNotNull("Field " + name + " is not yet declared!!", field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertNotNull(expClass+" '"+name+"' should be initialized with 'findViewById'",field);
|
||||||
|
assertEquals("Field '"+name+"' should be a "+expClass, expClass, field.getClass().getSimpleName());
|
||||||
|
//assertNotEquals(expClass+" '"+name+"' should be initialized with 'findViewById'",0,((View)field).getId());
|
||||||
|
return (View)field;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String testImageContent(View view, String expClass, ImageView.ScaleType scale, boolean bound) {
|
||||||
|
String viewName = testViewExist(view,expClass);
|
||||||
|
assertEquals("The scaleType in "+expClass+" with id="+viewName+" is should be "+scale.toString(),scale,((ImageView)view).getScaleType());
|
||||||
|
assertEquals("The adjustViewBounds in "+expClass+" with id="+viewName+" is should be "+bound,bound,((ImageView)view).getAdjustViewBounds());
|
||||||
|
return viewName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getImageResId(ImageView view) {
|
||||||
|
return Shadows.shadowOf(view.getDrawable()).getCreatedFromResId();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String testImageContent(View view, String src) {
|
||||||
|
Context context = view.getContext();
|
||||||
|
int srcId = context.getResources().getIdentifier(src, "drawable",context.getPackageName());
|
||||||
|
int actualId = getImageResId((ImageView)view);
|
||||||
|
String viewName = getViewName(view);
|
||||||
|
testItem(0,srcId==actualId,"The image source in "+view.getClass().getSimpleName()+
|
||||||
|
" with id='"+viewName+"' should be '"+src+"'.(jpg/png) in drawable resource", 3);
|
||||||
|
return viewName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String testImageContent(View view, String expClass, String src) {
|
||||||
|
String viewName = testViewExist(view,expClass);
|
||||||
|
Context context = view.getContext();
|
||||||
|
int srcId = context.getResources().getIdentifier(src, "drawable",context.getPackageName());
|
||||||
|
int actualId = getImageResId((ImageView)view);
|
||||||
|
assertEquals("The image source in "+expClass+" with id="+viewName+" is not '"+src+"'",srcId,actualId);
|
||||||
|
return viewName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean checkImageContent(View view, String src) {
|
||||||
|
Context context = view.getContext();
|
||||||
|
int srcId = context.getResources().getIdentifier(src, "drawable",context.getPackageName());
|
||||||
|
int actualId = getImageResId((ImageView)view);
|
||||||
|
return srcId==actualId;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String testImageContent(View view, String expClass, String src, ImageView.ScaleType scale, boolean bound) {
|
||||||
|
String viewName = testImageContent(view,expClass,src);
|
||||||
|
assertEquals("The scaleType in "+expClass+" with id="+viewName+" is should be "+scale.toString(),scale,((ImageView)view).getScaleType());
|
||||||
|
assertEquals("The adjustViewBounds in "+expClass+" with id="+viewName+" is should be "+bound,bound,((ImageView)view).getAdjustViewBounds());
|
||||||
|
return viewName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getValueOf(ArrayList<String> list) {
|
||||||
|
String str = "";
|
||||||
|
for (int i=0; i<list.size(); i++) {
|
||||||
|
str += list.get(i)+"-";
|
||||||
|
}
|
||||||
|
return str.substring(0,str.length()-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Uri getUriFromResource(int id, Activity main) {
|
||||||
|
Resources res = main.getResources();
|
||||||
|
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
|
||||||
|
"://" + res.getResourcePackageName(id)
|
||||||
|
+ '/' + res.getResourceTypeName(id) + '/' + res.getResourceEntryName(id) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testItem(Object expectVal, Object actualVal, String msg, int type) {
|
||||||
|
switch (type) {
|
||||||
|
case 1: assertEquals(msg,expectVal,actualVal);
|
||||||
|
break;
|
||||||
|
case 2: assertNotEquals(msg,expectVal,actualVal);
|
||||||
|
break;
|
||||||
|
case 3: assertTrue(msg,(boolean)actualVal);
|
||||||
|
break;
|
||||||
|
case 4: assertFalse(msg,(boolean)actualVal);
|
||||||
|
break;
|
||||||
|
case 5: assertNull(msg,actualVal);
|
||||||
|
break;
|
||||||
|
case 6: assertNotNull(msg,actualVal);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void failTest(String msg) {
|
||||||
|
fail(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getMethodsName(Method[] methods) {
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
for (int i=0; i<methods.length; i++) {
|
||||||
|
list.add(methods[i].getName());
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getRandomDouble(int min, int max) {
|
||||||
|
Random r = new Random();
|
||||||
|
return min + (max - min) * r.nextDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRandomInteger(int min, int max) {
|
||||||
|
Random r = new Random();
|
||||||
|
return min + r.nextInt(max - min + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getRandomArrayListString() {
|
||||||
|
return new ArrayList<String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public Object getFieldValue(Object obj, String fieldName) throws NoSuchFieldException,IllegalAccessException {
|
||||||
|
Field f = obj.getClass().getDeclaredField(fieldName);
|
||||||
|
f.setAccessible(true);
|
||||||
|
return f.get(obj);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getAccessName(int access) {
|
||||||
|
if (access== Modifier.PUBLIC) {
|
||||||
|
return "Public";
|
||||||
|
} else if (access== Modifier.PRIVATE) {
|
||||||
|
return "Private";
|
||||||
|
} else if (access== Modifier.PROTECTED) {
|
||||||
|
return "Protected";
|
||||||
|
} else if (access==17) {
|
||||||
|
return "Public Final";
|
||||||
|
} else if (access==18) {
|
||||||
|
return "Private Final";
|
||||||
|
} else {
|
||||||
|
return "No Information";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testField(Object obj, String fieldName, int access, Class<?> type, boolean isNull) {
|
||||||
|
Class<?> activityClass = obj.getClass();
|
||||||
|
Field f;
|
||||||
|
try {
|
||||||
|
f = activityClass.getDeclaredField(fieldName);
|
||||||
|
if (access>=0) assertEquals("Access to field \'"+fieldName+"\' must be "+getAccessName(access),access,f.getModifiers());
|
||||||
|
assertEquals("Type of field \'"+fieldName+"\' must be "+type.getSimpleName(), type, f.getType());
|
||||||
|
f.setAccessible(true);
|
||||||
|
if (isNull) {
|
||||||
|
assertNull("Field \'"+fieldName+"\' must be Null", f.get(obj));
|
||||||
|
} else {
|
||||||
|
assertNotNull("Field \'"+fieldName+"\' must be Constructed", f.get(obj));
|
||||||
|
}
|
||||||
|
} catch(Exception e) {
|
||||||
|
assertTrue("Field "+fieldName+" is not declared!!",false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Object getFieldObject(Object obj, String fieldname) {
|
||||||
|
try {
|
||||||
|
Field f = obj.getClass().getField(fieldname);
|
||||||
|
return f.get(obj);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getFieldValue(Object obj, String fieldName) {
|
||||||
|
Class<?> activityClass = obj.getClass();
|
||||||
|
Field f;
|
||||||
|
try {
|
||||||
|
f = activityClass.getDeclaredField(fieldName);
|
||||||
|
f.setAccessible(true);
|
||||||
|
return f.get(obj);
|
||||||
|
} catch(Exception e) {
|
||||||
|
String msg = UNDECLARED_CODE;
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testFieldValue(Activity activity, String fieldName, String className, Object value) {
|
||||||
|
Object field = getFieldValue(activity,fieldName);
|
||||||
|
if (field.getClass().getSimpleName().equals("String")) {
|
||||||
|
if (((String)field).equals(UNDECLARED_CODE)) {
|
||||||
|
fail("Field "+fieldName+" is not declared!!");
|
||||||
|
} else {
|
||||||
|
assertEquals("Field '"+fieldName+"' should be a "+className, className, field.getClass().getSimpleName());
|
||||||
|
assertEquals("Value of field '"+fieldName+"' must be "+value.toString(), field, value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
assertEquals("Field '"+fieldName+"' should be a "+className, className, field.getClass().getSimpleName());
|
||||||
|
assertEquals("Value of field '"+fieldName+"' must be "+value.toString(), field, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMethod(Object obj, String methodName, int access, Class[] params, Class<?> returnType) {
|
||||||
|
Class<?> activityClass = obj.getClass();
|
||||||
|
Method m;
|
||||||
|
try {
|
||||||
|
m = activityClass.getDeclaredMethod(methodName,params);
|
||||||
|
if (access>=0) assertEquals("Access to field \'"+methodName+"\' must be "+getAccessName(access),m.getModifiers(),access);
|
||||||
|
assertEquals("Type of return field \'"+methodName+"\' must be "+returnType.getSimpleName(), m.getReturnType(), returnType);
|
||||||
|
} catch(Exception e) {
|
||||||
|
assertTrue("Field "+methodName+" is not declared or parameters is wrong!!",false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String listToString(List x) {
|
||||||
|
String res = "";
|
||||||
|
for (int i=0; i<x.size(); i++){
|
||||||
|
res += x.get(i)+";";
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String arrayToString(Object[] x) {
|
||||||
|
String res = "";
|
||||||
|
for (int i=0; i<x.length; i++){
|
||||||
|
res += x[i]+";";
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHexColor(int x) {
|
||||||
|
return ("#" + Integer.toHexString(x).substring(2)).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String colorArrayToString(int[] x) {
|
||||||
|
String res = "";
|
||||||
|
for (int i=0; i<x.length; i++){
|
||||||
|
res += getHexColor(x[i])+";";
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getRandomString(int n) {
|
||||||
|
|
||||||
|
// chose a Character random from this String
|
||||||
|
String AlphaNumericString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
+ "0123456789"
|
||||||
|
+ "abcdefghijklmnopqrstuvxyz";
|
||||||
|
|
||||||
|
// create StringBuffer size of AlphaNumericString
|
||||||
|
StringBuilder sb = new StringBuilder(n);
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
|
||||||
|
// generate a random number between
|
||||||
|
// 0 to AlphaNumericString variable length
|
||||||
|
int index
|
||||||
|
= (int)(AlphaNumericString.length()
|
||||||
|
* Math.random());
|
||||||
|
|
||||||
|
// add Character one by one in end of sb
|
||||||
|
sb.append(AlphaNumericString
|
||||||
|
.charAt(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getButtonBgColor(Button button){
|
||||||
|
int buttonColor = 0;
|
||||||
|
|
||||||
|
if (button.getBackground() instanceof ColorDrawable) {
|
||||||
|
ColorDrawable cd = (ColorDrawable) button.getBackground();
|
||||||
|
buttonColor = cd.getColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button.getBackground() instanceof RippleDrawable) {
|
||||||
|
RippleDrawable rippleDrawable = (RippleDrawable) button.getBackground();
|
||||||
|
Drawable.ConstantState state = rippleDrawable.getConstantState();
|
||||||
|
try {
|
||||||
|
Field colorField = state.getClass().getDeclaredField("mColor");
|
||||||
|
colorField.setAccessible(true);
|
||||||
|
ColorStateList colorStateList = (ColorStateList) colorField.get(state);
|
||||||
|
buttonColor = colorStateList.getDefaultColor();
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buttonColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBgColor(RippleDrawable drawable){
|
||||||
|
int color=0;
|
||||||
|
Drawable.ConstantState state = drawable.getConstantState();
|
||||||
|
try {
|
||||||
|
Field colorField = state.getClass().getDeclaredField("mColor");
|
||||||
|
colorField.setAccessible(true);
|
||||||
|
ColorStateList colorStateList = (ColorStateList) colorField.get(state);
|
||||||
|
color = colorStateList.getDefaultColor();
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringResource(int id, Activity activity) {
|
||||||
|
return activity.getResources().getString(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringResource(String name, Activity activity) {
|
||||||
|
return getStringResource(getRscId(name,"string",activity),activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColorResource(int id, Activity activity) {
|
||||||
|
return ContextCompat.getColor(activity, id); //activity.getResources().getColor(id,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColorResource(String name, Activity activity) {
|
||||||
|
return getColorResource(getRscId(name,"color",activity),activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIntResource(int id, Activity activity) {
|
||||||
|
return activity.getResources().getInteger(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIntResource(String name, Activity activity) {
|
||||||
|
return getIntResource(getRscId(name,"integer",activity),activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getStringArrayResource(int id, Activity activity) {
|
||||||
|
return activity.getResources().getStringArray(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getStringArrayResource(String name, Activity activity) {
|
||||||
|
return getStringArrayResource(getRscId(name,"array",activity),activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getIntArrayResource(int id, Activity activity) {
|
||||||
|
return activity.getResources().getIntArray(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getIntArrayResource(String name, Activity activity) {
|
||||||
|
return getIntArrayResource(getRscId(name,"array",activity),activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public View getRootLayout(Activity activity) {
|
||||||
|
return ((ViewGroup)activity.getWindow().getDecorView()).getChildAt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCapitalFirstLetter(String str) {
|
||||||
|
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Method getMethodInObject(Object obj, String methodname, Class<?>... params) {
|
||||||
|
try {
|
||||||
|
Method m = obj.getClass().getMethod(methodname, params);
|
||||||
|
return m;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColorFromDrawable(Drawable d) {
|
||||||
|
if (d.getClass().getSimpleName().equals("ColorDrawable")) {
|
||||||
|
ColorDrawable cl = (ColorDrawable) d;
|
||||||
|
return cl.getColor();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public View getRootView(Activity activity) {
|
||||||
|
return ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user