Null point error on start of basic server

Using:Appium 2
Intellij as the IDE
Starts from the cmd line fine using the command: appium server -pa /wd/hub

Hi, I am doing some Appium training from a Blazemeter course and the have this test file, written the same way as the course (which runs)

package com.perforce;

import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.GeneralServerFlag;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Unit test for simple App.
 */
public class AppTest  {

    AppiumDriverLocalService appiumService;
    @Before
    public void startServer(){
        AppiumServiceBuilder appiumServiceBuilder = new AppiumServiceBuilder();
        appiumServiceBuilder.withArgument(GeneralServerFlag.BASEPATH, "/wd/hub");
        appiumServiceBuilder.usingAnyFreePort();
        appiumServiceBuilder.build();
        appiumService.start();
    }

    @Test
    public void serverTest(){
        System.out.println("Server test");
    }

    @After
    public void stopServer(){
        //appiumService.stop();
    }
}

When running this from the command line via Maven (as per the course) “mvn clean test” I get the following error

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.122 s <<< FAILURE! – in com.perforce.AppTest
[ERROR] com.perforce.AppTest.serverTest – Time elapsed: 1.069 s <<< ERROR!
java.lang.NullPointerException
at java.base/java.io.FileOutputStream.(FileOutputStream.java:227)
at java.base/java.io.FileOutputStream.(FileOutputStream.java:185)
at org.openqa.selenium.remote.service.DriverService$Builder.getLogOutput(DriverService.java:448)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:495)
at com.perforce.AppTest.startServer(AppTest.java:22)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.RunBefores.invokeMethod(RunBefores.java:33)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:316)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:240)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:214)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] AppTest.startServer:22 ┬╗ NullPointer
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.081 s
[INFO] Finished at: 2023-09-18T09:04:30+12:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.1.2:test (default-test) on project Appium2DemoProject:
[ERROR]
[ERROR] Please refer to C:\Temp\MavenProject\Appium2DemoProject\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Any ideas please?

Can someone explain this to me

How does “GeneralServerFlag.BASEPATH” tell it where appium is ?

Worked out why it was failing, it needed to have the following line added

.withLogFile(new File( “C:\Temp\MavenProject\Appium2DemoProject\test.txt”));

It was throwing the null pointer exception because it didn;t have a log file to write to, no clear and obvious error message for people who are not developer centric.

Edit - to which it has not added any content yet too in about 5 runs