示例#1
0
  public BodyDeclaration getTreeNode() {
    //        System.out.println("Building Method " + node.getName());

    String finalName = name + type.name() + Config.get().getTestMethodSuffix();
    MethodDeclaration result = new MethodDeclaration(ModifierSet.PUBLIC, new VoidType(), finalName);

    result.setComment(
        new BlockComment(
            "\n\t\tGenerated Unity test\n\t\t" + name + " - " + type.name() + " test." + "\n\t"));

    AnnotationExpr anno = new MarkerAnnotationExpr(new NameExpr("Test"));
    List<AnnotationExpr> annoList = new ArrayList<>();
    annoList.add(anno);
    result.setAnnotations(annoList);

    BlockStmt body = new BlockStmt();
    List<Statement> statements = new ArrayList<>();
    statements.add(instance.getStatement());

    body.setStmts(statements);
    result.setBody(body);

    // Set any mocks
    // Set instance
    // Set call parameters
    // Set call result
    // Set assertions
    return result;
  }
 @Test
 public void testInsertUpdateDelete() {
   TestType testData = new TestType();
   testData.setData("test");
   if (seriesReferenceDao.hasData("datasetname")) {
     seriesReferenceDao.delete(DataTypeEnum.BIOTIC, "datasetname", true);
   } else {
     seriesReferenceDao.insert(
         "writeRole", "unrestricted", "imr", DataTypeEnum.BIOTIC, "datasetname", testData, true);
     seriesReferenceDao.insert(
         "writeRole", "unrestricted", "imr", DataTypeEnum.BIOTIC, "datasetname2", testData, true);
     seriesReferenceDao.delete(DataTypeEnum.BIOTIC, "datasetname", true);
   }
   int numBefore = seriesReferenceDao.getDatasets().getDataset().size();
   seriesReferenceDao.insert(
       "writeRole", "unrestricted", "imr", DataTypeEnum.BIOTIC, "datasetname", testData, true);
   int numAfter = seriesReferenceDao.getDatasets().getDataset().size();
   assertEquals(numBefore + 1, numAfter);
   TestType testRes = seriesReferenceDao.get("datasetname");
   assertEquals(testData.getData(), testRes.getData());
 }
  /*
   * Test thread stack trace dumping
   */
  @Test
  public void testActivityCounter() throws InterruptedException {

    Integer maxNumThreadDumps = 3;

    Logger logger = Logger.getLogger("test");
    StatsTracker<TestType> tracker =
        new StatsTracker<TestType>(TestType.values(), logger, 2, 1, maxNumThreadDumps, 100);

    /*
     * If there is only one concurrent thread, there should be no thread
     * dumps.
     */
    for (int i = 0; i < 20; i++) {
      long startA = tracker.markStart();
      Thread.sleep(10);
      tracker.markFinish(TestType.GET, startA);
    }

    /* Did we see some thread dumps? */
    assertEquals(0, tracker.getNumCompletedDumps());

    /*
     * Simulate three concurrent threads. There should be automatic thread
     * dumping, because the tracker is configured to dump when there are
     * more than two concurrent threads with operations of > 1 ms.
     */
    for (int i = 0; i < 20; i++) {
      long startA = tracker.markStart();
      long startB = tracker.markStart();
      long startC = tracker.markStart();
      Thread.sleep(10);
      tracker.markFinish(TestType.GET, startA);
      tracker.markFinish(TestType.GET, startB);
      tracker.markFinish(TestType.GET, startC);
    }

    long expectedMaxDumps = maxNumThreadDumps;

    /* Did we see some thread dumps? */
    assertTrue(tracker.getNumCompletedDumps() > 1);
    assertTrue(tracker.getNumCompletedDumps() <= expectedMaxDumps);
  }
 /**
  * The test type for the specified device pool.
  *
  * <p>Allowed values include the following:
  *
  * <ul>
  *   <li>
  *       <p>BUILTIN_FUZZ: The built-in fuzz type.
  *   <li>
  *       <p>BUILTIN_EXPLORER: For Android, an app explorer that will traverse an Android app,
  *       interacting with it and capturing screenshots at the same time.
  *   <li>
  *       <p>APPIUM_JAVA_JUNIT: The Appium Java JUnit type.
  *   <li>
  *       <p>APPIUM_JAVA_TESTNG: The Appium Java TestNG type.
  *   <li>
  *       <p>APPIUM_PYTHON: The Appium Python type.
  *   <li>
  *       <p>APPIUM_WEB_JAVA_JUNIT: The Appium Java JUnit type for Web apps.
  *   <li>
  *       <p>APPIUM_WEB_JAVA_TESTNG: The Appium Java TestNG type for Web apps.
  *   <li>
  *       <p>APPIUM_WEB_PYTHON: The Appium Python type for Web apps.
  *   <li>
  *       <p>CALABASH: The Calabash type.
  *   <li>
  *       <p>INSTRUMENTATION: The Instrumentation type.
  *   <li>
  *       <p>UIAUTOMATION: The uiautomation type.
  *   <li>
  *       <p>UIAUTOMATOR: The uiautomator type.
  *   <li>
  *       <p>XCTEST: The XCode test type.
  *   <li>
  *       <p>XCTEST_UI: The XCode UI test type.
  * </ul>
  *
  * @param testType The test type for the specified device pool.
  *     <p>Allowed values include the following:
  *     <ul>
  *       <li>
  *           <p>BUILTIN_FUZZ: The built-in fuzz type.
  *       <li>
  *           <p>BUILTIN_EXPLORER: For Android, an app explorer that will traverse an Android app,
  *           interacting with it and capturing screenshots at the same time.
  *       <li>
  *           <p>APPIUM_JAVA_JUNIT: The Appium Java JUnit type.
  *       <li>
  *           <p>APPIUM_JAVA_TESTNG: The Appium Java TestNG type.
  *       <li>
  *           <p>APPIUM_PYTHON: The Appium Python type.
  *       <li>
  *           <p>APPIUM_WEB_JAVA_JUNIT: The Appium Java JUnit type for Web apps.
  *       <li>
  *           <p>APPIUM_WEB_JAVA_TESTNG: The Appium Java TestNG type for Web apps.
  *       <li>
  *           <p>APPIUM_WEB_PYTHON: The Appium Python type for Web apps.
  *       <li>
  *           <p>CALABASH: The Calabash type.
  *       <li>
  *           <p>INSTRUMENTATION: The Instrumentation type.
  *       <li>
  *           <p>UIAUTOMATION: The uiautomation type.
  *       <li>
  *           <p>UIAUTOMATOR: The uiautomator type.
  *       <li>
  *           <p>XCTEST: The XCode test type.
  *       <li>
  *           <p>XCTEST_UI: The XCode UI test type.
  * @see TestType
  */
 public void setTestType(TestType testType) {
   this.testType = testType.toString();
 }
 @Override
 public int hashCode() {
   int hash = super.hashCode();
   hash += (testType != null ? testType.hashCode() : 0);
   return hash;
 }
 public void setTestType(TestType testType) {
   this.testType = testType;
   if (testType != null) {
     setCreator(testType.getCreator());
   }
 }
 public static <V> Collection<TestEvent<V>> create(TestType type, V value, V prev) {
   return Arrays.asList(
       TestEvent.create(type.lambdaType(), value, prev),
       TestEvent.create(type.listenerType(), value, prev));
 }