0

我正在尝试查找程序中正在调用的所有外部函数的列表。被测程序在包中net.sf.gaeappmanager.google.appengine,外部函数在.的包和子包中org.apache.http..

为此,我编写了以下方面:

public pointcut capturehttp() :
    within(net.sf.gaeappmanager..*) && 
    !within(gaeAspect) &&
    (
        call(* org.apache.http..*+.*(..)) ||
        call(org.apache.http..*+.new(..))
    );

after() : capturehttp() {
    System.out.println(
        "Function of http Package" +
        thisJoinPoint.getSignature().getName()
    );
}

但这方面并没有发挥应有的作用。它抛出未处理的异常。如果我只使用System.out.println("Function of http Package")没有thisJoinPoint那么它工作正常。

根据@kriegaex 的要求添加了额外信息

我正在使用通过 Evosuite 工具生成的测试用例执行 PUT。首先,我在这里包括测试用例:

@Test
  public void test0()  throws Throwable  {
      // Undeclared exception!
      try { 
        Manager.retrieveAppQuotaDetails("@;[", ")C)!L{Fy,b%<$%", "@;[", ")C)!L{Fy,b%<$%");
        fail("Expecting exception: NoClassDefFoundError");

      } catch(NoClassDefFoundError e) {
         //
         // org/apache/commons/logging/LogFactory
         //
         assertThrownBy("org.apache.http.impl.client.AbstractHttpClient", e);
      }
  }

  //Test case number: 1
  /*
   * 1 covered goal:
   * Goal 1. net.sf.gaeappmanager.google.appengine.Manager.<init>()V: root-Branch
   */

  @Test
  public void test1()  throws Throwable  {
      Manager manager0 = new Manager();
  }
}

当我执行这个测试用例(上面给出的方面)时,我得到了以下异常:

There were 2 failures:
1) test1(net.sf.gaeappmanager.google.appengine.Manager_ESTest)
java.lang.NoClassDefFoundError: Could not initialize class net.sf.gaeappmanager.
google.appengine.Manager
        at net.sf.gaeappmanager.google.appengine.Manager_ESTest.test1(Manager_ES
Test.java:48)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framework
Method.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCal
lable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMe
thod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMet
hod.java:17)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.
java:26)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.ja
va:27)
        at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement
.call(FailOnTimeout.java:298)
        at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement
.call(FailOnTimeout.java:292)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.lang.Thread.run(Thread.java:745)
2) test0(net.sf.gaeappmanager.google.appengine.Manager_ESTest)
java.lang.AssertionError: Exception was not thrown in org.apache.http.impl.clien
t.AbstractHttpClient
        at org.evosuite.runtime.EvoAssertions.assertThrownBy(EvoAssertions.java:
70)
        at net.sf.gaeappmanager.google.appengine.Manager_ESTest.test0(Manager_ES
Test.java:36)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framework
Method.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCal
lable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMe
thod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMet
hod.java:17)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.
java:26)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.ja
va:27)
        at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement
.call(FailOnTimeout.java:298)
        at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement
.call(FailOnTimeout.java:292)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.lang.Thread.run(Thread.java:745)

FAILURES!!!
Tests run: 2,  Failures: 2

如果我执行相同的测试用例但在方面没有thisJoinPoint,我会得到以下结果:

.

.Function of http Package
Time: 0.669
OK (2 tests)

我主要关心的是为什么在方面中添加thisJoinPoint会导致异常以及如何获取程序中所有外部函数的列表。

4

0 回答 0