A Plain Old Java project in Android Studio, with JUnit 5 Create Project --------------------------- 1. File > New project; "No Activity"; Next Set name (ex: "Assignment 1"), Set package name (Ex: ca.cmpt276.as1), Set Save location to the path you want for your projects Set language to Java Minimum SDK API 21 (others likely OK) Finish Wait for project to finish building (stops saying "loading...") 2. Create new module: File > New > Module > "Java or Kotlin Library" Module (near bottom of list on left) Library name: :lib:GameModule Package Name: ca.cmpt276.as1 (for example) Class Name: MyClass Finish 3. Open GameModule/build.gradle of Java module; change source/target compatibility to 1.8 ** IMPORTANT ** When building a Java only project (like assignment 1): At bottom of /GameModule/build.gradle file, add: test { useJUnitPlatform() } This solves the error: "Test events were not received" FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':lib:GameModule:test'. > No tests found for given includes: [ca.cmpt276.gamemodule.PlayerScoreTest](filter.includeTestsMatching) When building a full Android project (vs Java only), see troubleshooting below. 4. Build Java Only (no Android) - Open settings.gradle and comment out "include ':app'" Save file. "Sync Now" when prompted at the top of the settings.gradle file. (This will switches the project view out of 'Android' view and into 'Project') - Explore code: lib --> GameModule --> src -> main ->....->MyClass - Add main() - Run it 5. Setup JUnit 5 - Under GameModule/src, create a folder named: test/java/ - Right click GameModule/src/test/java/ folder, select Mark Directory As..., Test Sources Root [may be done already] - Create a test for the module's code: Open MyClass (alt-enter on the class name to create JUnit test class); Create test... Select Testing Library: JUnit5 Click OK - Alt-enter on the JUnit error in the include statement; --> Add JUnit 5.x.x to classpath - File > Project Structure > Dependencies : change GameModel's dependency to be a concrete version of JUnit5. Requested Version: 5.9.0 (for example, or newer) Configuration: implementation OK (Should rebuild project) - Write a test or two - Run the JUnit tests (execute the test file) and it should show you its progress. 6. Coding text UI: - Use provided source code on course website for getting some input/output going. - Make main print to screen, read in user input with Scanner. Trouble Shooting ---------------- - When you run your project you get errors with scanner - Open settings.gradle file and comment out the line: include ':app' (add // before it) - When trying to run tests you see: No tasks available Solution: Place your test classes in the correct location: 1. Right click on the /GameModule/src/ folder and select New --> Folder; name it "test" This should likely create a /GameModule/src/test/java folder as well; if not, create the java/ folder as well 2. The /GameModule/src/test/java/ folder should be green, which means a test root If it's not green, right click the /GameModule/src/test/java/ folder; --> Mark Directory As --> Test Sources Root 3. Inside /GameModule/src/test/java create a package with the same name as your class-under-test's package 4. Move your Tester1.java file into this new test package - When trying to run tests you see: FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':lib:GameModule:test'. > No tests found for given includes: [ca.cmpt276.gamemodule.PlayerScoreTest](filter.includeTestsMatching) Solutions: 1. See note about useJUnitPlatform() above. 2. Ensure package name is all lower case (fix by right-clicking package, select Refactor --> Rename Package) - If using JUnit 5 inside an Android Project (i.e., not just for Java), If you encounter the error: "Test events were not received" FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:testDebugUnitTest'. > No tests found for given includes: [....](--tests filter) then instead of putting `useJUnitPlatform()`.. in the build.gradle, do: 1. Open your module's build.gradle file 2. Edit the android{...} block to include a testOptions{} sub-block: android { compileSdkVersion 32 ... testOptions { unitTests.all { useJUnitPlatform() } } }