增加测试
This commit is contained in:
parent
a5ace97cb4
commit
f4ad73518b
|
|
@ -31,7 +31,9 @@ android {
|
|||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
testOptions {
|
||||
unitTests.returnDefaultValues = true
|
||||
}
|
||||
configurations.configureEach {
|
||||
resolutionStrategy {
|
||||
force 'com.squareup.okhttp3:okhttp:3.12.13'
|
||||
|
|
@ -49,4 +51,9 @@ dependencies {
|
|||
implementation 'com.google.zxing:core:3.3.0'
|
||||
implementation 'com.orhanobut:logger:2.2.0'
|
||||
implementation 'org.jsoup:jsoup:1.15.3'
|
||||
|
||||
// Required -- JUnit 4 framework
|
||||
testImplementation 'junit:junit:4.12'
|
||||
// Optional -- Mockito framework(可选,用于模拟一些依赖对象,以达到隔离依赖的效果)
|
||||
testImplementation 'org.mockito:mockito-core:5.12.0'
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
import android.app.Application;
|
||||
|
||||
import com.github.catvod.crawler.Spider;
|
||||
import com.github.catvod.spider.Init;
|
||||
import com.github.catvod.spider.Zxzj;
|
||||
import com.github.catvod.utils.Json;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ZxzjTest {
|
||||
@Mock
|
||||
private Application mockContext;
|
||||
|
||||
private Zxzj spider;
|
||||
|
||||
@org.junit.Before
|
||||
public void setUp() throws Exception {
|
||||
Init.init(mockContext);
|
||||
spider = new Zxzj();
|
||||
spider.init(mockContext, "");
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void homeContent() throws Exception {
|
||||
String content = spider.homeContent(true);
|
||||
JsonObject map = Json.safeObject(content);
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
System.out.println("homeContent--" + gson.toJson(map));
|
||||
|
||||
Assert.assertFalse(map.getAsJsonArray("list").isEmpty());
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void categoryContent() throws Exception {
|
||||
String content = spider.categoryContent("/list/1.html", "2", true, null);
|
||||
JsonObject map = Json.safeObject(content);
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
System.out.println("categoryContent--" + gson.toJson(map));
|
||||
Assert.assertFalse(map.getAsJsonArray("list").isEmpty());
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void detailContent() throws Exception {
|
||||
|
||||
String content = spider.detailContent(Arrays.asList("/detail/4463.html"));
|
||||
JsonObject map = Json.safeObject(content);
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
System.out.println("detailContent--" + gson.toJson(map));
|
||||
Assert.assertFalse(map.getAsJsonArray("list").isEmpty());
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void searchContent() throws Exception {
|
||||
String content = spider.playerContent("", "/video/4463-1-1.html", new ArrayList<>());
|
||||
JsonObject map = Json.safeObject(content);
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
System.out.println("searchContent--" + gson.toJson(map));
|
||||
Assert.assertFalse(map.getAsJsonArray("list").isEmpty());
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void playerContent() throws Exception {
|
||||
String content = spider.searchContent("我的人间烟火", false);
|
||||
JsonObject map = Json.safeObject(content);
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
System.out.println("playerContent--" + gson.toJson(map));
|
||||
Assert.assertFalse(map.getAsJsonArray("list").isEmpty());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue