Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock java.io.File instances #23

Closed
ArnoldGuo opened this issue Aug 1, 2014 · 1 comment
Closed

Mock java.io.File instances #23

ArnoldGuo opened this issue Aug 1, 2014 · 1 comment
Assignees

Comments

@ArnoldGuo
Copy link

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants