🐻
berkeley
  • #Despair
  • 16A/B
    • Thevenin and Norton Equivalence
    • Resistive Touchscreen
    • Trilateration and Correlation
    • RC Circuits & Transient Analysis
  • 61B
    • Testing
    • References in Java
    • Linked Lists in Java
    • Implementation Inheritance
    • Comparables and Iterators
    • Casting
    • Lists and Sets
    • Asymptotics
    • Trees
    • Hashing
    • PriorityQueue and Heap
    • Graphs, Tree Traversals
    • Tries
    • Sorting
  • Discrete Mathematics
    • Sets + Mathematical Notation
    • Logic and Proofs
    • Induction
    • Cryptography/RSA
    • Modular Arithmetic
    • Discrete Probability
  • Linear Algebra
    • Linear Equations
    • Matrix Algebra
    • Determinants
    • Vector Spaces
    • Eigenvectors and Eigenvalues
    • Projections and Orthogonality
    • SVD/PCA
  • Math 275 — Ordinary Differential Equations
    • Math 275 — Overview
    • Modeling via Differential Equations
    • Linear Systems
  • INTEGBI 35AC
    • Humans Came From Fish
    • Evolution's History
    • Typology
    • The Human Diaspora
  • 170
    • Basics
    • Divide and Conquer
    • Fast Fourier Transform
    • Graphs
    • Greedy
  • 61C
    • Pointers and Memory
    • Floating Point
    • Compliation, Assembly, Linking, Loading
    • RISC-V, Assembly
Powered by GitBook
On this page
  • Test-Driven Development
  • Testing in Java

Was this helpful?

  1. 61B

Testing

Adapted from 61B's coursework.

Test-Driven Development

  • Identify a new feature, and write a unit test for it.

  • Run the failing test.

  • Write code that passes the test

  • Refactor the code, making it faster, easier to read, or accounting for more cases.

Testing in Java

Testing in Java is simple using the JUnit library. Here is an example of a possible test.

@org.jnunit.Test
public void testMethod() {
    Object[] input = {"before"};
    Object[] expected = {"after"};
    method(input);
    org.junit.Assert.assertArrayEquals(expected, input);
}

The test above would be a possible one for a method that mutates an array to something else.

Tests using JUnit may not be static methods.

Using Intellij, these tests can be run individually or all at once. Combined with the debugger, students can avoid "autograder driven development," which entails of basically relying on the autograder to churn out code that will, eventually, be correct.

You can run these tests all at once or individually in IntelliJ.

PreviousRC Circuits & Transient AnalysisNextReferences in Java

Last updated 4 years ago

Was this helpful?