コード例 #1
0
  @Test
  public void shouldUnderstandTwoTestsInARow() {
    metric.calculate(
        toInputStream(
            "import a.b.Dep1;"
                + "class BlaTest {"
                + "@Test "
                + "public void aSimpleTest1() {"
                + "Dep1 x = new Dep1();"
                + "Bla obj = new Bla(x, 1, 3.5, \"bla\");"
                + "obj.method1();"
                + "assertEquals(obj.isAbc());"
                + "}"
                + "@Test "
                + "public void aSimpleTest2() {"
                + "Dep2 x = new Dep2();"
                + "Bla obj = new Bla(x, 1, 3.5, \"bla\");"
                + "obj.method1();"
                + "assertEquals(obj.isAbc());"
                + "}"
                + "}"));

    assertTrue(metric.getTests().get("aSimpleTest1").isIntegration());
    assertFalse(metric.getTests().get("aSimpleTest2").isIntegration());
  }
コード例 #2
0
  @Test
  public void someRealExampleFromJUnit() {

    metric.calculate(
        toInputStream(
            "package org.junit.tests.junit3compatibility;"
                + ""
                + "import static org.junit.Assert.assertNull;"
                + ""
                + "import org.junit.Test;"
                + "import org.junit.internal.builders.SuiteMethodBuilder;"
                + ""
                + "public class ClassRequestTest {"
                + "    public static class PrivateSuiteMethod {"
                + "        static junit.framework.Test suite() {"
                + "            return null;"
                + "        }"
                + "    }"
                + ""
                + "    @Test"
                + "    public void noSuiteMethodIfMethodPrivate() throws Throwable {"
                + "        assertNull(new SuiteMethodBuilder()"
                + "                .runnerForClass(PrivateSuiteMethod.class));"
                + "    }"
                + "}"));

    assertTrue(metric.getTests().get("noSuiteMethodIfMethodPrivate").isIntegration());
  }
コード例 #3
0
  @Test
  public void shouldTellThatIsUnitTestIfMethodFromSamePackageIsInvokedCompletlelyInline() {
    metric.calculate(
        toInputStream(
            "class BlaTest {"
                + "@Test "
                + "public void aSimpleTest() {"
                + "assertEquals(new Dep1().doMagic());"
                + "}"
                + "}"));

    assertFalse(metric.getTests().get("aSimpleTest").isIntegration());
  }
コード例 #4
0
  @Test
  public void
      shouldTellThatIsAUnitTestIfConstructorReceivesConcreteAndPrimitiveStuffFromSamePackage() {
    metric.calculate(
        toInputStream(
            "class BlaTest {"
                + "@Test "
                + "public void aSimpleTest() {"
                + "Dep1 x = new Dep1();"
                + "Bla obj = new Bla(x, 1, 3.5, \"bla\");"
                + "obj.method1();"
                + "assertEquals(obj.isAbc());"
                + "}"
                + "}"));

    assertFalse(metric.getTests().get("aSimpleTest").isIntegration());
  }
コード例 #5
0
  @Test
  public void shouldTellThatIsAUnitTestIfConcreteMethodFromSamePackageIsInvoked() {
    metric.calculate(
        toInputStream(
            "class BlaTest {"
                + "@Test "
                + "public void aSimpleTest() {"
                + "Dep1 newX = new Dep1();"
                + "Bla obj = new Bla();"
                + "newX.doMagic();"
                + "obj.doOtherMagic();"
                + "assertEquals(obj.isAbc());"
                + "}"
                + "}"));

    assertFalse(metric.getTests().get("aSimpleTest").isIntegration());
  }
コード例 #6
0
  @Test
  public void shouldTellThatIsAnIntegrationTestIfConcreteMethodIsInvokedWithoutInstance() {
    metric.calculate(
        toInputStream(
            "import a.b.Dep1;"
                + "class BlaTest {"
                + "@Test "
                + "public void aSimpleTest() {"
                + "Bla obj = new Bla();"
                + "int result = new Dep1().doMagic();"
                + "new Dep1().doMagic2();"
                + "assertEquals(obj.isAbc());"
                + "}"
                + "}"));

    assertTrue(metric.getTests().get("aSimpleTest").isIntegration());
  }
コード例 #7
0
  @Test
  public void shouldTellThatIsAnUnitTestIfMethodReceivesConcreteStuffFromSamePackage() {
    metric.calculate(
        toInputStream(
            "class BlaTest {"
                + "@Test "
                + "public void aSimpleTest() {"
                + "Dep1 x = new Dep1();"
                + "Dep2 y = new Dep2();"
                + "Bla obj = new Bla(x);"
                + "obj.method1(y);"
                + "assertEquals(obj.isAbc());"
                + "}"
                + "}"));

    assertFalse(metric.getTests().get("aSimpleTest").isIntegration());
  }
コード例 #8
0
  @Test
  public void shouldTellThatIsAnIntegrationTestIfConstructorReceivesConcreteStuffWithCtor() {
    metric.calculate(
        toInputStream(
            "import a.b.Dep1;"
                + "import a.b.Dep2;"
                + "class BlaTest {"
                + "@Test "
                + "public void aSimpleTest() {"
                + "Dep1 x = new Dep1(new TT());"
                + "Dep2 y = new Dep2(new KK());"
                + "Bla obj = new Bla(x, y);"
                + "obj.method1();"
                + "assertEquals(obj.isAbc());"
                + "}"
                + "}"));

    assertTrue(metric.getTests().get("aSimpleTest").isIntegration());
  }
コード例 #9
0
  @Test
  public void pequeninho() {
    metric.calculate(
        toInputStream(
            "import a.b.Dep1;"
                + "import a.b.Dep2;"
                + "class BlaTest {"
                + "@Test "
                + "public void aSimpleTest() {"
                + "Dep1 x = new Dep1();"
                + "Dep2 y = new Dep2();"
                + "Bla obj = new Bla(x, y);"
                + "obj.method1();"
                + "assertEquals(obj.isAbc());"
                + "}"
                + "}"));

    assertTrue(metric.getTests().get("aSimpleTest").isIntegration());
  }