How to write unit tests for java static methods in Android Studio project?

Опубликовано: 12 Май 2024
на канале: Programmer World
130
4

In this video, it shows the steps to create java unit test for static methods of Android Studio Project.


I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: [email protected]

Complete source code and other details/ steps of this video are posted in the below link:
https://programmerworld.co/android/ho...


However, the main Java code is copied below also for reference:

package com.programmerworld.unittestsforstaticmethod;

import org.junit.Test;
import static org.junit.Assert.*;

public class ExampleUnitTest {
private MainActivity activity;
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}

@Test
public void testStaticAdditionMethod(){
double result = activity.staticAdditionMethod(4,5);
assertEquals(9,result,0.0001);
}
}

--