jmockit / jmockit1

Advanced Java library for integration testing, mocking, faking, and code coverage
Other
461 stars 239 forks source link

Mock java.io.File instances #23

Closed ArnoldGuo closed 10 years ago

ArnoldGuo commented 10 years ago

import java.io.File;

import mockit.Mocked; import mockit.NonStrictExpectations;

import org.testng.annotations.Test;

public class MockFileInvestigation {

@Test
public void test(@Mocked File f1) {
    new NonStrictExpectations() {
    };
}

}

When run this, the log shows the test passed, however with an NullPointerException. pls check the log:

[TestNG] Running: /tmp/testng-eclipse-1285965114/testng-customsuite.xml

PASSED: test("")

Default test
Tests run: 1, Failures: 0, Skips: 0

Default suite

Total tests run: 1, Failures: 0, Skips: 0

[TestNG] Time taken by org.testng.reporters.EmailableReporter2@19f9e414: 13 ms [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@261b66ea: 88 ms [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@5076ec1a: 5 ms [TestNG] Reporter org.testng.reporters.XMLReporter@13707ac failed java.lang.NullPointerException at org.testng.reporters.XMLStringBuffer.addCDATA(XMLStringBuffer.java:297) at org.testng.reporters.XMLSuiteResultWriter.addParameter(XMLSuiteResultWriter.java:266) at org.testng.reporters.XMLSuiteResultWriter.addTestMethodParams(XMLSuiteResultWriter.java:250) at org.testng.reporters.XMLSuiteResultWriter.addTestResult(XMLSuiteResultWriter.java:154) at org.testng.reporters.XMLSuiteResultWriter.addTestResults(XMLSuiteResultWriter.java:130) at org.testng.reporters.XMLSuiteResultWriter.writeAllToBuffer(XMLSuiteResultWriter.java:74) at org.testng.reporters.XMLSuiteResultWriter.writeSuiteResult(XMLSuiteResultWriter.java:52) at org.testng.reporters.XMLReporter.writeSuiteToBuffer(XMLReporter.java:120) at org.testng.reporters.XMLReporter.writeSuite(XMLReporter.java:86) at org.testng.reporters.XMLReporter.generateReport(XMLReporter.java:63) at org.testng.TestNG.generateReports(TestNG.java:1094) at org.testng.TestNG.run(TestNG.java:1053) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175) [TestNG] Time taken by org.testng.reporters.jq.Main@5f83bcb8: 74 ms

This issue leads to maven build fail. If change the class to other class, it works ok.

I tried to create test for one method, it is similar to the sample code: http://jmockit.googlecode.com/svn/trunk/www/tutorial/BehaviorBasedTesting.html#argumentMatching

Part: Instances created with a given constructor

But what I need mock are several file instances.

Cannot find any anywhere, would you please kindly do me a favor and let me know this is an issue or my misunderstanding?

Thanks.

rliesenfeld commented 10 years ago

I added the example test class to a Maven module having TestNG tests. When executed through Maven, I am not seeing any exceptions. Can you provide a pom.xml file as well? Maybe then I can reproduce the problem.