简体   繁体   中英

Junit using ant

I have a class that looks like this:

---imports---

class ErroringClass {

/* methods*/
main{}

}

Update

public class TestErroringClass {

static ArrayList<Integer> arrayTestTimes;
static ErroringClass main = new ErroringClass ();

@Test
public test{}

 .
 .
 .
}

Testcase: initializationError took 0.002 sec Caused an ERROR The class ErrorTestClass is not public. java.lang.Exception: The class ErrorTestClass is not public. at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

Testcase: initializationError took 0 sec Caused an ERROR Test class should have exactly one public constructor java.lang.Exception: Test class should have exactly one public constructor at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

<!-- Testsuite -->
<target name="test" depends="compile" >
    <junit fork="yes" 
           description="Unit Tests"
           showoutput="true"
           printsummary="true"
           outputtoformatters="true" filtertrace="on">
        <classpath>
            <path refid="classpath.test"/>
            <pathelement location="${main.build.dir}"/>
            <pathelement location="${test.build.dir}"/>
        </classpath>

        <test name="ErrorTestClass" outfile="./output" >
            <!-- <formatter type="brief" usefile="true" /> -->
            <formatter type="plain" usefile="true" />
        </test>
    </junit>
</target>

Trying to run my test from ant and not getting them to see all my files that are in one file to keep the source as accessible following the rules in design. What am I missing?

Updated

Testsuite: ErrorTestClass
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.104 sec 
------------- Standard Output ---------------
[]
------------- ---------------- ---------------
Testcase: Test1 took 0.001 sec
Testcase: Test2 took 0 sec
Testcase: Test3 took 0 sec
Testcase: Test4 took 0 sec
Testcase: Test5 took 0 sec
Testcase: stringTestNull took 0.001 sec
Testcase: stringTestTrue took 0 sec
Testcase: assertNullTest took 0 sec

It because ErrorTestClass has package level access (default visibility modifier). Change it to public class ErrorTestClass .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM