Skip to content

Commit

Permalink
update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou9584 committed Dec 29, 2023
1 parent aff72ed commit d4f5b12
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected Set<TestRunDevice> chooseDevices(Task task) {
return chosenDevices;
}

Task.RunnerType runningType = Task.RunnerType.valueOf(testTask.getRunnerType());
String runningType = testTask.getRunnerType();
if (((Task.RunnerType.APPIUM_CROSS.name().equals(runningType)) || (Task.RunnerType.T2C_JSON.name().equals(runningType))) && devices.size() > 1) {
Optional<DeviceInfo> mainDeviceInfo = devices.stream().filter(deviceInfo -> !DeviceType.WINDOWS.name().equals(deviceInfo.getType())).findFirst();
Assert.isTrue(mainDeviceInfo.isPresent(), "There are more than 1 device, but all of them is windows device!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CommandActionLoaderTest extends BaseTest {
@Test
void testAttachCommandAction() {
TestTask testTask = new TestTask();
testTask.setTestSuite("com.microsoft.test");
testTask.setTaskAlias("com.microsoft.test");
commandLoader.loadCommandAction(testTask);
Assertions.assertEquals(testTask.getDeviceActions().size(), 2, "Analysis commands failed!");
Assertions.assertEquals(testTask.getDeviceActions().get("setUp").size(), 4, "Analysis commands failed!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.microsoft.hydralab.agent.runner;

import com.microsoft.hydralab.agent.runner.espresso.EspressoRunner;
import com.microsoft.hydralab.agent.service.TestTaskEngineService;
import com.microsoft.hydralab.agent.test.BaseTest;
import com.microsoft.hydralab.common.entity.common.DeviceInfo;
import com.microsoft.hydralab.common.entity.common.Task;
Expand All @@ -9,7 +10,10 @@
import com.microsoft.hydralab.common.entity.common.TestRunDevice;
import com.microsoft.hydralab.common.entity.common.TestTask;
import com.microsoft.hydralab.common.entity.common.TestTaskSpec;
import com.microsoft.hydralab.common.management.AgentManagementService;
import com.microsoft.hydralab.common.management.device.DeviceType;
import com.microsoft.hydralab.common.util.ADBOperateUtil;
import com.microsoft.hydralab.performance.PerformanceTestManagementService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand All @@ -20,10 +24,19 @@
import java.io.File;

public class TestRunnerTest extends BaseTest {
@Resource
EspressoRunner espressoRunner;
final Logger logger = LoggerFactory.getLogger(TestRunnerTest.class);

@Resource
TestRunDeviceOrchestrator testRunDeviceOrchestrator;
@Resource
AgentManagementService agentManagementService;
@Resource
TestTaskEngineService testTaskEngineService;
@Resource
PerformanceTestManagementService performanceTestManagementService;
@Resource
ADBOperateUtil adbOperateUtil;

@Test
public void createTestRunnerAndInitDeviceTest() {

Expand All @@ -38,7 +51,8 @@ public void createTestRunnerAndInitDeviceTest() {
TestTask testTask = new TestTask();
testTask.setResourceDir(resourceDir);
testTask.setTestSuite("TestSuite");

EspressoRunner espressoRunner = new EspressoRunner(agentManagementService, testTaskEngineService, testRunDeviceOrchestrator, performanceTestManagementService,
adbOperateUtil);
TestRunDevice testRunDevice = new TestRunDevice(deviceInfo, deviceInfo.getType());
testRunDevice.setLogger(logger);
TestRun testRun = espressoRunner.initTestRun(testTask, testRunDevice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.microsoft.hydralab.agent.runner.analysis.scanner.apk.ApkCanaryExecutor;
import com.microsoft.hydralab.agent.test.BaseTest;
import com.microsoft.hydralab.common.entity.common.scanner.ApkReport;
import com.microsoft.hydralab.common.util.FileUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -14,16 +15,17 @@ public class ApkCanaryExecutorTest extends BaseTest {

@Test
public void testApkCanaryExecutor() {
File apkFilePath = new File("C:\\Users\\zhoule\\Downloads\\Link_to_Windows_1.23102.199.0_Apkpure.apk");
File apkFilePath = new File("../common/src/test/resources/record_release.apk");
Assertions.assertTrue(apkFilePath.exists(), "apk file not exist: " + apkFilePath.getAbsolutePath());
ApkCanaryExecutor apkCanaryExecutor = new ApkCanaryExecutor(new File(""));
File workingDir = new File("../common/src/test/resources/apk_canary");
ApkCanaryExecutor apkCanaryExecutor = new ApkCanaryExecutor(workingDir);
ApkReport apkReport = new ApkReport("apkReport");
apkReport = apkCanaryExecutor.analyzeApk(
apkReport,
apkFilePath.getAbsolutePath(),
baseLogger

);
FileUtil.deleteFileRecursively(workingDir);
System.out.println(JSON.toJSONString(apkReport, SerializerFeature.PrettyFormat));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.microsoft.hydralab.agent.service;

import com.microsoft.hydralab.agent.runner.TestRunnerManager;
import com.microsoft.hydralab.agent.runner.espresso.EspressoRunner;
import com.microsoft.hydralab.agent.test.BaseTest;
import com.microsoft.hydralab.common.entity.common.DeviceInfo;
import com.microsoft.hydralab.common.entity.common.Task;
Expand All @@ -16,7 +15,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.ApplicationContext;

import javax.annotation.Resource;
Expand All @@ -27,8 +25,6 @@ public class TestTaskEngineServiceTest extends BaseTest {

@Resource
TestTaskEngineService testTaskEngineService;
@MockBean
EspressoRunner espressoRunner;
@Resource
ApplicationContext applicationContext;

Expand Down Expand Up @@ -82,7 +78,7 @@ public void runTestTask() {

TestTask testTask = new TestTask(taskSpecForGroupDevice);
testTask = (TestTask) testTaskEngineService.runTestTask(testTask);
Assertions.assertEquals(0, testTask.getTaskRunList(), "TestTask TestDevicesCount should be 0 as no device is available");
Assertions.assertEquals(0, testTask.getDeviceCount(), "TestTask TestDevicesCount should be 0 as no device is available");
Assertions.assertEquals(4, testTask.getDeviceActions().get("setUp").size(),
"TestTask setUp DeviceActions should be 4 according to the config in application-test.yml");

Expand Down

0 comments on commit d4f5b12

Please sign in to comment.