Я пытаюсь сделать модульный тест для моей функции с изменением значений некоторых атрибутов, когда я запускаю модульный тест, он выдает ошибку ниже
java .lang.NullPointerException в com.example. spotifyclone.MusicActivityTest.setMusicPlayerComponents (MusicActivityTest. java: 31) в sun.reflect.NativeMethodAccessorImpl.invoke0 (нативный метод) в sun.reflect.NativeMethodAccessorImpl.inforce.infid. invoke (DelegatingMethodAccessorImpl. java: 43) в java .lang.reflect.Method.invoke (Method. java: 498) в org.junit.platform.commons.util.ReflectionUtils.invokeMethod (ReflectionUtils. * 1013) *: 532) в org.junit.jupiter.engine.execution.ExecutableInvoker.invoke (ExecutableInvoker. java: 115) в org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda $ invokeTestMethodor $ 6 (тестировать). : 171) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute (ThrowableCollector. java: 72) в org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod (TestMethodTestDescriptor. java: 167) в org.junit.jupiter.engine.descriptor. в org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute (TestMethodTestDescriptor. java: 59) в org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda $ executeTec * * 10T. ) в org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute (ThrowableCollector. java: 72) в org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively: узел Node0.10. ) в org.junit.platform.engine.support.hierarchical.NodeTestTask.execute (NodeTestTask. java: 74) в java .util.ArrayList.forEach (ArrayList. java: 1257) в орг.junit. platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll (SameThreadHierarchicalTestExecutorService. java: 38) в org.junit.platform.en gine.support.hierarchical.NodeTestTask.lambda $ executeRecursively $ 4 (NodeTestTask. java: 112) в org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute (ThrowableCollector. *7228*) на уровне 72 .platform.engine.support.hierarchical.NodeTestTask.executeRecurtively (NodeTestTask. java: 98) в org.junit.platform.engine.support.hierarchical.NodeTestTask.execute (NodeTestTask: * 10 * в * 10 * в 10:30) .util.ArrayList.forEach (ArrayList. java: 1257) в org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll (SameThreadHierarchicalTestExecutorService. javasu.en. at.it. 38. at. .hierarchical.NodeTestTask.lambda $ executeRecursively $ 4 (NodeTestTask. java: 112) в org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute (ThrowableCollector. java: 72). org.p. engine.support.hierarchical.NodeTestTask.executeRecurtively (NodeTestTask. java: 98) в org.junit.platform.engine.support.hierarchical.NodeTestTa sk.execute (NodeTestTask. java: 74) в org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit (SameThreadHierarchicalTestExecutorService. java: 32) в org.form.w.inh. HierarchicalTestExecutor.execute (HierarchicalTestExecutor. java: 57) по адресу org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute (HierarchicalTestEngine. java: 51) по адресу org.junitefher.cl execute (DefaultLauncher. java: 220) в org.junit.platform.launcher.core.DefaultLauncher.lambda $ execute $ 6 (DefaultLauncher. java: 188) в org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStream (DefaultLauncher. java: 202) в org.junit.platform.launcher.core.DefaultLauncher.execute (DefaultLauncher. java: 181) в org.junit.platform.launcher.core. DefaultLauncher.execute (DefaultLauncher. java: 128) по адресу com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs (JUnit5IdeaTestRunner. java: 69) по адресу com.intellner.rt.executionTuner java: 47) в com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart (JUnitStarter. java: 242) в com.intellij.rt.execution.junit.JUnitStarter.main (JUnitStarter *: JUnitStarter: 70)
Вот мой код ниже
import static org.junit.jupiter.api.Assertions.*;
@RunWith(RobolectricTestRunner.class)
class MusicActivityTest {
MusicActivity music;
@Before
public void setUp() throws Exception {
music = new MusicActivity(RuntimeEnvironment.application.getApplicationContext());
}
@Test
void setMusicPlayerComponents() {
music.setMusicPlayerComponents("aa","aa","0","","","");
assertEquals(music.name_song.getText(),"aa");
}